Skip to content

Commit 65b4da7

Browse files
committed
Adds tmp socket to prevent GC from deleting it
1 parent b6448f6 commit 65b4da7

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

services/web/server/src/simcore_service_webserver/studies_access.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,38 +55,45 @@ async def get_public_project(app: web.Application, project_uuid: str):
5555
return prj
5656

5757

58-
# TODO: from .users import create_temporary_user
5958
async def create_temporary_user(request: web.Request):
6059
"""
6160
TODO: user should have an expiration date and limited persmissions!
6261
"""
6362
from .login.cfg import get_storage
64-
from .login.handlers import ACTIVE, GUEST
63+
from .login.handlers import ACTIVE, GUEST, ANONYMOUS
6564
from .login.utils import get_client_ip, get_random_string
6665
from .security_api import encrypt_password
67-
68-
# from .utils import generate_passphrase
69-
# from .utils import generate_password
66+
from .resource_manager.websocket_manager import WebsocketRegistry
7067

7168
db = get_storage(request.app)
7269

7370
# TODO: avatar is an icon of the hero!
74-
# FIXME: # username = generate_passphrase(number_of_words=2).replace(" ", "_").replace("'", "")
7571
username = get_random_string(min_len=5)
7672
email = username + "@guest-at-osparc.io"
7773
password = get_random_string(min_len=12)
7874

75+
# creates a user that is marked as ANONYMOUS
7976
user = await db.create_user(
8077
{
8178
"name": username,
8279
"email": email,
8380
"password_hash": encrypt_password(password),
8481
"status": ACTIVE,
85-
"role": GUEST,
82+
"role": ANONYMOUS,
8683
"created_ip": get_client_ip(request),
8784
}
8885
)
8986

87+
# creates an entry in the socket's registry to avoid garbage collector (GC) deleting it
88+
# See https://github.com/ITISFoundation/osparc-simcore/issues/1853
89+
registry = WebsocketRegistry(user["id"], f"{username}-guest-session", request.app)
90+
await registry.set_socket_id(f"{username}-guest-socket-id")
91+
92+
# Now that we know the ID, we set the user as GUEST
93+
# This extra step is to prevent the possibility that the GC is cleaning while
94+
# the function above is creating the entry in the socket
95+
await db.update_user(user, updates={"role": GUEST})
96+
9097
return user
9198

9299

0 commit comments

Comments
 (0)