Skip to content

Commit aee07f9

Browse files
committed
cleanup
1 parent ba14597 commit aee07f9

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

services/web/server/src/simcore_service_webserver/groups/_groups_db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from sqlalchemy.engine.row import Row
2828
from sqlalchemy.ext.asyncio import AsyncConnection
2929

30-
from ..db.models import GroupType, groups, user_to_groups, users
30+
from ..db.models import groups, user_to_groups, users
3131
from ..db.plugin import get_asyncpg_engine
3232
from ..users.exceptions import UserNotFoundError
3333
from .exceptions import (

services/web/server/src/simcore_service_webserver/studies_dispatcher/_users.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import string
1414
from contextlib import suppress
1515
from datetime import datetime
16+
from typing import Final
1617

1718
import redis.asyncio as aioredis
1819
from aiohttp import web
@@ -65,6 +66,33 @@ async def get_authorized_user(request: web.Request) -> dict:
6566
return {}
6667

6768

69+
# GUEST_USER_RC_LOCK:
70+
#
71+
# These locks prevents the GC from deleting a GUEST user in to stages of its lifefime:
72+
#
73+
# 1. During construction:
74+
# - Prevents GC from deleting this GUEST user while it is being created
75+
# - Since the user still does not have an ID assigned, the lock is named with his random_user_name
76+
# - the timeout here is the TTL of the lock in Redis. in case the webserver is overwhelmed and cannot create
77+
# a user during that time or crashes, then redis will ensure the lock disappears and let the garbage collector do its work
78+
#
79+
MAX_DELAY_TO_CREATE_USER: Final[int] = 5 # secs
80+
#
81+
# 2. During initialization
82+
# - Prevents the GC from deleting this GUEST user, with ID assigned, while it gets initialized and acquires it's first resource
83+
# - Uses the ID assigned to name the lock
84+
#
85+
MAX_DELAY_TO_GUEST_FIRST_CONNECTION: Final[int] = 15 # secs
86+
#
87+
#
88+
# NOTES:
89+
# - In case of failure or excessive delay the lock has a timeout that automatically unlocks it
90+
# and the GC can clean up what remains
91+
# - Notice that the ids to name the locks are unique, therefore the lock can be acquired w/o errors
92+
# - These locks are very specific to resources and have timeout so the risk of blocking from GC is small
93+
#
94+
95+
6896
async def create_temporary_guest_user(request: web.Request):
6997
"""Creates a guest user with a random name and
7098
@@ -86,33 +114,6 @@ async def create_temporary_guest_user(request: web.Request):
86114
password = generate_password(length=12)
87115
expires_at = datetime.utcnow() + settings.STUDIES_GUEST_ACCOUNT_LIFETIME
88116

89-
# GUEST_USER_RC_LOCK:
90-
#
91-
# These locks prevents the GC from deleting a GUEST user in to stages of its lifefime:
92-
#
93-
# 1. During construction:
94-
# - Prevents GC from deleting this GUEST user while it is being created
95-
# - Since the user still does not have an ID assigned, the lock is named with his random_user_name
96-
# - the timeout here is the TTL of the lock in Redis. in case the webserver is overwhelmed and cannot create
97-
# a user during that time or crashes, then redis will ensure the lock disappears and let the garbage collector do its work
98-
#
99-
MAX_DELAY_TO_CREATE_USER = 5 # secs
100-
#
101-
# 2. During initialization
102-
# - Prevents the GC from deleting this GUEST user, with ID assigned, while it gets initialized and acquires it's first resource
103-
# - Uses the ID assigned to name the lock
104-
#
105-
MAX_DELAY_TO_GUEST_FIRST_CONNECTION = 15 # secs
106-
#
107-
#
108-
# NOTES:
109-
# - In case of failure or excessive delay the lock has a timeout that automatically unlocks it
110-
# and the GC can clean up what remains
111-
# - Notice that the ids to name the locks are unique, therefore the lock can be acquired w/o errors
112-
# - These locks are very specific to resources and have timeout so the risk of blocking from GC is small
113-
#
114-
115-
# (1) read details above
116117
usr = None
117118
try:
118119
async with redis_locks_client.lock(

0 commit comments

Comments
 (0)