diff --git a/services/web/server/src/simcore_service_webserver/studies_dispatcher/_errors.py b/services/web/server/src/simcore_service_webserver/studies_dispatcher/_errors.py index 3d5326a8606..eb04db2b924 100644 --- a/services/web/server/src/simcore_service_webserver/studies_dispatcher/_errors.py +++ b/services/web/server/src/simcore_service_webserver/studies_dispatcher/_errors.py @@ -26,3 +26,7 @@ class InvalidRedirectionParams(PydanticErrorMixin, StudyDispatcherError): "The link you provided is invalid because it doesn't contain any information related to data or a service." " Please check the link and make sure it is correct." ) + + +class GuestUsersLimitError(PydanticErrorMixin, StudyDispatcherError): + msg_template = "Maximum number of guests was reached. Please login with a registered user or try again later" diff --git a/services/web/server/src/simcore_service_webserver/studies_dispatcher/_studies_access.py b/services/web/server/src/simcore_service_webserver/studies_dispatcher/_studies_access.py index aa8d60b4e8c..10f7d1bc275 100644 --- a/services/web/server/src/simcore_service_webserver/studies_dispatcher/_studies_access.py +++ b/services/web/server/src/simcore_service_webserver/studies_dispatcher/_studies_access.py @@ -40,7 +40,8 @@ MSG_TOO_MANY_GUESTS, MSG_UNEXPECTED_ERROR, ) -from ._users import MaxGuestUsersError, create_temporary_guest_user, get_authorized_user +from ._errors import GuestUsersLimitError +from ._users import create_temporary_guest_user, get_authorized_user _logger = logging.getLogger(__name__) @@ -288,7 +289,7 @@ async def get_redirection_to_study_page(request: web.Request) -> web.Response: user = await create_temporary_guest_user(request) is_anonymous_user = True - except MaxGuestUsersError as exc: + except GuestUsersLimitError as exc: # # NOTE: Creation of guest users is limited. For that # reason we respond with 429 and inform the user that temporarily diff --git a/services/web/server/src/simcore_service_webserver/studies_dispatcher/_users.py b/services/web/server/src/simcore_service_webserver/studies_dispatcher/_users.py index ae1688f08ec..da1b2372705 100644 --- a/services/web/server/src/simcore_service_webserver/studies_dispatcher/_users.py +++ b/services/web/server/src/simcore_service_webserver/studies_dispatcher/_users.py @@ -35,6 +35,7 @@ from ..users.api import get_user from ..users.exceptions import UserNotFoundError from ._constants import MSG_GUESTS_NOT_ALLOWED +from ._errors import GuestUsersLimitError from .settings import StudiesDispatcherSettings, get_plugin_settings _logger = logging.getLogger(__name__) @@ -60,14 +61,6 @@ async def get_authorized_user(request: web.Request) -> dict: return {} -class MaxGuestUsersError(RuntimeError): - # NOTE: when lock times out it is because a user cannot - # be create in less that MAX_DELAY_TO_CREATE_USER seconds. - # That shows that the system is really loaded and we rather - # stop creating GUEST users. - ... - - async def create_temporary_guest_user(request: web.Request): """Creates a guest user with a random name and @@ -141,6 +134,11 @@ async def create_temporary_guest_user(request: web.Request): ).acquire() except LockNotOwnedError as err: + # NOTE: when lock times out it is because a user cannot + # be create in less that MAX_DELAY_TO_CREATE_USER seconds. + # That shows that the system is really loaded and we rather + # stop creating GUEST users. + # NOTE: here we cleanup but if any trace is left it will be deleted by gc if usr.get("id"): @@ -155,9 +153,7 @@ async def _cleanup(draft_user): APP_FIRE_AND_FORGET_TASKS_KEY ], ) - - msg = f"Load limit reached. Unable to create a user under {MAX_DELAY_TO_CREATE_USER} sec." - raise MaxGuestUsersError(msg) from err + raise GuestUsersLimitError from err return user