Error in cloudflare workers : Uncaught (in response) Error: The script will never generate a response
Asked Answered
E

0

9

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, ctx: ExecutionContext) {
        const client = new Client({/*details*/})
        await client.connect()
        const {
            rows: [{ now }]
        } = await client.query('select now();')
        ctx.waitUntil(client.end())
        return new Response(now)
    }
}

About the problem, I have found the following page but it does not mention any solution https://zuplo.com/blog/the-script-will-never-generate-a-response-on-cloudflare-workers/

There is no unreturned code here so I'm not supposed to see this error

Earley answered 18/3, 2023 at 19:23 Comment(3)
There isn't anything obviously wrong with the code you posted, but of course the implementation details of the neondatabase/serverless library matter. Does it share promises between clients, like described in that blog post? Or maybe it has a bug where it's legitimately hanging? It looks like someone (you?) opened an issue there which seems like the right next step.Tijuanatike
I just started running into this in development and the code in question also makes use of the @neondatabase/serverless package. I suspect the problem is coming from there.Robert
I'm getting this to, but I'm not using Neon, I'm using Hyperdrive. I have an endpoint that successfully outputs data from my DB the first time. But if I call the endpoint again soon after, I get this error.Electrosurgery

© 2022 - 2024 — McMap. All rights reserved.