Skip to content

Commit e69fc22

Browse files
committed
Catches all db errors
1 parent fcc46ca commit e69fc22

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from itertools import chain
55
from typing import Dict, List, Optional, Tuple
66

7+
import asyncpg.exceptions
78
import psycopg2
89
from aiohttp import web
910
from aioredlock import Aioredlock
@@ -48,6 +49,7 @@
4849
from .registry import RedisResourceRegistry, get_registry
4950

5051
logger = logging.getLogger(__name__)
52+
database_errors = (psycopg2.DatabaseError, asyncpg.exceptions.PostgresError)
5153

5254

5355
def setup_garbage_collector(app: web.Application):
@@ -58,6 +60,7 @@ async def _setup_background_task(app: web.Application):
5860

5961
yield
6062

63+
logger.info("Stopping garbage collector...")
6164
# on_cleanup
6265
with suppress(asyncio.CancelledError):
6366
cgp_task.cancel()
@@ -235,14 +238,15 @@ async def remove_disconnected_user_resources(
235238

236239
if resource_name == "project_id":
237240
# inform that the project can be closed on the backend side
241+
# WARNING: slot functions can raise any exception
238242
await emit(
239243
event="SIGNAL_PROJECT_CLOSE",
240244
user_id=None,
241245
project_uuid=resource_value,
242246
app=app,
243247
)
244248

245-
# if this user was a GUEST also remove it from the database
249+
# ONLY GUESTS: if this user was a GUEST also remove it from the database
246250
# with the only associated project owned
247251
await remove_guest_user_with_all_its_resources(
248252
app=app,
@@ -375,7 +379,7 @@ async def remove_guest_user_with_all_its_resources(
375379
await remove_all_projects_for_user(app=app, user_id=user_id)
376380
await remove_user(app=app, user_id=user_id)
377381

378-
except psycopg2.DatabaseError:
382+
except database_errors:
379383
logger.warning(
380384
"Could not remove GUEST with id=%s. Check the logs above for details",
381385
user_id,
@@ -570,7 +574,7 @@ async def replace_current_owner(
570574
app=app, primary_gid=int(new_project_owner_gid)
571575
)
572576

573-
except psycopg2.DatabaseError:
577+
except database_errors:
574578
logger.exception(
575579
"Could not recover new user id from gid %s", new_project_owner_gid
576580
)
@@ -598,7 +602,7 @@ async def replace_current_owner(
598602
project_data=project,
599603
project_uuid=project_uuid,
600604
)
601-
except psycopg2.DatabaseError:
605+
except database_errors:
602606
logger.exception(
603607
"Could not remove old owner and replaced it with user %s",
604608
new_project_owner_id,
@@ -609,7 +613,7 @@ async def remove_user(app: web.Application, user_id: int) -> None:
609613
"""Tries to remove a user, if the users still exists a warning message will be displayed"""
610614
try:
611615
await delete_user(app, user_id)
612-
except psycopg2.DatabaseError:
616+
except database_errors:
613617
logger.warning(
614618
"User '%s' still has some projects, could not be deleted", user_id
615619
)

0 commit comments

Comments
 (0)