Skip to content

Commit f9d2c1e

Browse files
committed
Catches all db errors
1 parent 44b4dd2 commit f9d2c1e

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

+9-5
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,
@@ -392,7 +396,7 @@ async def remove_guest_user_with_all_its_resources(
392396
await remove_all_projects_for_user(app=app, user_id=user_id)
393397
await remove_user(app=app, user_id=user_id)
394398

395-
except psycopg2.DatabaseError:
399+
except database_errors:
396400
logger.warning(
397401
"Could not remove GUEST with id=%s. Check the logs above for details",
398402
user_id,
@@ -587,7 +591,7 @@ async def replace_current_owner(
587591
app=app, primary_gid=int(new_project_owner_gid)
588592
)
589593

590-
except psycopg2.DatabaseError:
594+
except database_errors:
591595
logger.exception(
592596
"Could not recover new user id from gid %s", new_project_owner_gid
593597
)
@@ -615,7 +619,7 @@ async def replace_current_owner(
615619
project_data=project,
616620
project_uuid=project_uuid,
617621
)
618-
except psycopg2.DatabaseError:
622+
except database_errors:
619623
logger.exception(
620624
"Could not remove old owner and replaced it with user %s",
621625
new_project_owner_id,
@@ -626,7 +630,7 @@ async def remove_user(app: web.Application, user_id: int) -> None:
626630
"""Tries to remove a user, if the users still exists a warning message will be displayed"""
627631
try:
628632
await delete_user(app, user_id)
629-
except psycopg2.DatabaseError:
633+
except database_errors:
630634
logger.warning(
631635
"User '%s' still has some projects, could not be deleted", user_id
632636
)

0 commit comments

Comments
 (0)