From cb828fc60513570db4230280cb3de998d0ed9c45 Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Mon, 2 Mar 2026 20:23:26 -0800 Subject: [PATCH] fix: add retry logic to EncryptID database init for Docker networking delays Docker container networking can take a moment to stabilize even after depends_on health checks pass. This adds 5 retries with exponential backoff (2s, 4s, 6s, 8s, 10s) to survive transient CONNECT_TIMEOUT errors. Co-Authored-By: Claude Opus 4.6 --- src/encryptid/server.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/encryptid/server.ts b/src/encryptid/server.ts index 001d928..85a31ac 100644 --- a/src/encryptid/server.ts +++ b/src/encryptid/server.ts @@ -3454,11 +3454,23 @@ app.get('/', (c) => { // DATABASE INITIALIZATION & SERVER START // ============================================================================ -// Initialize database on startup -initDatabase().catch(err => { - console.error('EncryptID: Failed to initialize database', err); - process.exit(1); -}); +// Initialize database on startup with retries (Docker networking may take a moment) +(async () => { + const maxRetries = 5; + for (let attempt = 1; attempt <= maxRetries; attempt++) { + try { + await initDatabase(); + return; + } catch (err) { + console.error(`EncryptID: Database init attempt ${attempt}/${maxRetries} failed:`, (err as Error).message); + if (attempt === maxRetries) { + console.error('EncryptID: All database init attempts exhausted, exiting'); + process.exit(1); + } + await new Promise(r => setTimeout(r, attempt * 2000)); + } + } +})(); // Clean expired challenges and recovery tokens every 10 minutes setInterval(() => {