-
-
Notifications
You must be signed in to change notification settings - Fork 285
Description
Issue
In Cloudflare Workers, using a module-level singleton DB client over TCP can fail on subsequent requests.
The first request succeeds, but after idle time the TCP connection is closed. A subsequent request reuses the stale client and hangs until Workers cancels the request with:
The Workers runtime canceled this request because it detected that your Worker's code had hung and would never generate a response.
Ref: https://developers.cloudflare.com/workers/observability/errors/
Fix
In Workers, a request-scoped TCP DB client should be created , so idle/stale connections are not reused and do not crash the worker.
Notes
The issue only surfaces when using TCP, but I think the sane default would be to always scope the instance to the request (in workers) and not worry about detecting the driver.