Skip to content

Commit d41f02a

Browse files
authored
Merge pull request #90 from OpenMined/fix/container-health
fix: graceful db shutdown and correct Docker healthcheck URL
2 parents 9f63f55 + 1fd70d4 commit d41f02a

4 files changed

Lines changed: 10 additions & 2 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ ENV PATH="/app/.venv/bin:$PATH" \
8787
EXPOSE 8080
8888

8989
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
90-
CMD python -c "import os; import urllib.request; urllib.request.urlopen(f'http://localhost:{os.getenv(\"SYFT_PORT\", \"8080\")}/health')" || exit 1
90+
CMD python -c "import os; import urllib.request; urllib.request.urlopen(f'http://localhost:{os.getenv(\"SYFT_PORT\", \"8080\")}/api/v1/health')" || exit 1
9191

9292
ENTRYPOINT ["/bin/sh", "-c", "exec python -m uvicorn syft_space.main:app --host 0.0.0.0 --port ${SYFT_PORT:-8080}"]

backend/syft_space/components/shared/database.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ def set_sqlite_pragma(dbapi_conn, connection_record):
100100
cursor.close()
101101
# logger.debug("SQLite PRAGMA foreign_keys=ON set for new connection")
102102

103+
async def dispose(self) -> None:
104+
"""Dispose of the engine and close all pooled connections."""
105+
await self.engine.dispose()
106+
logger.info("Database engine disposed")
107+
103108
@asynccontextmanager
104109
async def get_session(self) -> AsyncGenerator[SQLModelAsyncSession, None]:
105110
"""Get an async session for the database"""

backend/syft_space/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ async def lifespan(app: FastAPI):
298298
except Exception as e:
299299
logger.error(f"Error shutting down {name}: {e}")
300300

301+
# 9. Dispose database engine (close all pooled connections)
302+
await database.dispose()
303+
301304

302305
# Initialize FastAPI app
303306
app = FastAPI(

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ services:
5555

5656
# Health check using Python (no curl in distroless image)
5757
healthcheck:
58-
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8080/health')"]
58+
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8080/api/v1/health')"]
5959
interval: 30s
6060
timeout: 10s
6161
retries: 3

0 commit comments

Comments
 (0)