Skip to content

Commit 855dea4

Browse files
committed
Add exta delay to TTL at redirection
1 parent 354c595 commit 855dea4

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

services/web/server/src/simcore_service_webserver/resource_manager/websocket_manager.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _resource_key(self) -> Dict[str, str]:
4545
else "*",
4646
}
4747

48-
async def set_socket_id(self, socket_id: str) -> None:
48+
async def set_socket_id(self, socket_id: str, *, extra_tll: int = 0) -> None:
4949
log.debug(
5050
"user %s/tab %s adding socket %s in registry...",
5151
self.user_id,
@@ -54,9 +54,9 @@ async def set_socket_id(self, socket_id: str) -> None:
5454
)
5555
registry = get_registry(self.app)
5656
await registry.set_resource(self._resource_key(), (SOCKET_ID_KEY, socket_id))
57-
# hearthbeat is not emulated in tests, make sure that with very small GC intervals
58-
# the resources do not result as timeout; this value is usually in the order of minutes
59-
timeout = max(3, get_service_deletion_timeout(self.app))
57+
# NOTE: hearthbeat is not emulated in tests, make sure that with very small GC intervals
58+
# the resources do not expire; this value is usually in the order of minutes
59+
timeout = max(3, get_service_deletion_timeout(self.app)) + abs(extra_tll)
6060
await registry.set_key_alive(self._resource_key(), timeout)
6161

6262
async def get_socket_id(self) -> Optional[str]:

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,21 @@ async def activate_as_guest_user(user: Dict, app: web.Application):
9191
from .login.handlers import GUEST, ANONYMOUS
9292
from .resource_manager.websocket_manager import WebsocketRegistry
9393

94+
# Save time to allow user to be redirected back and not being deleted by GC
95+
# SEE https://github.com/ITISFoundation/osparc-simcore/pull/1928#discussion_r517176479
96+
EXTRA_TIME_TO_COMPLETE_REDIRECT = 3
97+
9498
if user.get("role") == ANONYMOUS:
9599
db = get_storage(app)
96100
username = user["name"]
97101

98102
# creates an entry in the socket's registry to avoid garbage collector (GC) deleting it
99-
# See https://github.com/ITISFoundation/osparc-simcore/issues/1853
103+
# SEE https://github.com/ITISFoundation/osparc-simcore/issues/1853
104+
#
100105
registry = WebsocketRegistry(user["id"], f"{username}-guest-session", app)
101-
await registry.set_socket_id(f"{username}-guest-socket-id")
106+
await registry.set_socket_id(
107+
f"{username}-guest-socket-id", extra_tll=EXTRA_TIME_TO_COMPLETE_REDIRECT
108+
)
102109

103110
# Now that we know the ID, we set the user as GUEST
104111
# This extra step is to prevent the possibility that the GC is cleaning while

0 commit comments

Comments
 (0)