Skip to content

fix(api): avoid worker-hanging db reuse#25

Merged
risu729 merged 1 commit into
mainfrom
codex-20260520-fix-worker-hang
May 20, 2026
Merged

fix(api): avoid worker-hanging db reuse#25
risu729 merged 1 commit into
mainfrom
codex-20260520-fix-worker-hang

Conversation

@risu729
Copy link
Copy Markdown
Member

@risu729 risu729 commented May 20, 2026

Summary

  • stop caching the Postgres/Drizzle client in Worker global scope
  • create request-local Postgres.js clients with SSL, disabled type introspection, and short idle lifetime
  • keep realtime WebSocket auth from performing a DB user upsert before the upgrade

Why

Live tail logs still showed 1101 cancellations on /api/realtime, and live curls showed the same cancellation on DB-backed public routes like /api/pois. Cloudflare's runtime can cancel requests when a Promise is tied to global or stale request-context I/O and can never settle. The previous DB singleton kept the Postgres client in module scope across Worker requests; realtime auth also hit that DB path before upgrading the socket.

Verification

  • bun run check
  • live observed before fix: GET /api/pois returns Cloudflare 1101 on current deployment

@risu729 risu729 marked this pull request as ready for review May 20, 2026 01:03
@risu729 risu729 merged commit 0f6ae9d into main May 20, 2026
1 check passed
@risu729 risu729 deleted the codex-20260520-fix-worker-hang branch May 20, 2026 01:03
risu729 added a commit that referenced this pull request May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant