Immutable solution version
Error in cloudflare workers : Uncaught (in response) Error: The script will never generate a response
Complete solution
How to fix 'Error in cloudflare workers : Uncaught (in response) Error: The script will never generate a response' in Neon, straight from the verified resolution in gh:neondatabase/serverless#11. Root cause plus what to change.
What was reported
Issue neondatabase/serverless#11 (closed, 17 comments): Hi I’m getting the following error in Cloudflare workers
A hanging Promise was canceled. This happens when the worker runtime is waiting for a Promise from JavaScript to resolve, but has detected that the Promise cannot possibly ever resolve because all code and events related to the Promise's I/O context have already finished. ✘ [ERROR] Uncaught (in response) Error: The script will never generate a response.My code is simple
import { Client } from '@neondatabase/serverless'
import { Env } from './models'
export default {
async fetch(request: Request, env: Env
## The verified resolution
[jawj (maintainer)]: Do not keep a Pool/Client alive between requests on Cloudflare Workers - each invocation is isolated and the worker kills promises tied to a finished request's I/O context ('The script will never generate a response'). Create the Pool inside the fetch/request handler. Same symptom occurs locally when the connection string env var is undefined (put env vars in `.dev.vars` for `wrangler dev`), and newer driver versions surface connect errors more helpfully instead of hanging.Evidence
Asked in gh:neondatabase/serverless#11 (https://github.com/neondatabase/serverless/issues/11): Error in cloudflare workers : Uncaught (in response) Error: The script will never generate a response. The issue report: Issue neondatabase/serverless#11 (closed, 17 comments): Hi I’m getting the following error in Cloudflare workers
A hanging Promise was canceled. This happens when the worker runtime is waiting for a Promise from JavaScript to resolve, but has detected that the Promise cannot possibly ever resolve because all code and events related to the Promise's I/O context have already finished. ✘ [ERROR] Uncaught (in response) Error: The script will never generate a response.My code is simple
import { Client } from '@neondatabase/serverless'
import { Env } from './models'
export default {
async fetch(request: Request, env: Env The verified answer: [jawj (maintainer)]: Do not keep a Pool/Client alive between requests on Cloudflare Workers - each invocation is isolated and the worker kills promises tied to a finished request's I/O context ('The script will never generate a response'). Create the Pool inside the fetch/request handler. Same symptom occurs locally when the connection string env var is undefined (put env vars in `.dev.vars` for `wrangler dev`), and newer driver versions surface connect errors more helpfully instead of hanging.By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_NrvaztO_W-7WWTgKbCokIw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Error in cloudflare workers : Uncaught (in response) Error: The script will never generate a response <span>— Vectle</span></a>