Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 31e5497

Browse files
committed
fix(backend): log database status during authentication and server startup
1 parent bc9d183 commit 31e5497

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

services/backend/src/hooks/authHook.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ export async function authHook(
2020
// Check if database is configured before attempting authentication
2121
const dbStatus = getDbStatus();
2222
if (!dbStatus.configured || !dbStatus.initialized) {
23-
// Database not ready, skip authentication
23+
// Database not ready, skip authentication - log this for debugging
24+
request.log.warn({
25+
operation: 'auth_hook',
26+
dbConfigured: dbStatus.configured,
27+
dbInitialized: dbStatus.initialized,
28+
dialect: dbStatus.dialect
29+
}, 'Auth hook: Database not ready, skipping authentication');
2430
request.user = null;
2531
request.session = null;
2632
return;

services/backend/src/server.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,20 @@ export const createServer = async () => {
748748
}
749749
}
750750
});
751-
751+
752+
// Verify database is ready before allowing server to accept requests
753+
// This prevents workers from accepting requests before database is initialized
754+
const finalDbStatus = getDbStatus();
755+
if (!finalDbStatus.configured || !finalDbStatus.initialized) {
756+
server.log.error({
757+
operation: 'startup_check',
758+
dbConfigured: finalDbStatus.configured,
759+
dbInitialized: finalDbStatus.initialized,
760+
dialect: finalDbStatus.dialect
761+
}, 'Database not ready at startup - refusing to start server');
762+
process.exit(1);
763+
}
764+
server.log.info('Database ready, server initialization complete');
765+
752766
return server;
753767
}

0 commit comments

Comments
 (0)