porsager / porsager/postgres

Fails with `Error: The script will never generate a response.` on cloudflare pages

Open
#1,013 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
8.7k
Forks
374
Avg merge
11d 16h
Merged PRs (30d)
1

Description

This is similar to #865, however unlike in that issue I create the postgres client on each request and still get following error on cloudflare pages with "compatibility_flags": ["nodejs_compat"]

✘ [ERROR] 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.
[wrangler:inf] GET /api/test 500 Internal Server Error (8ms)
✘ [ERROR] Uncaught (in response) Error: The script will never generate a response.

Using it as follows

app.get("/api/test", async (c) => {
  console.log("test route");
  const sql = postgres(c.env.DATABASE_URL);
  const users = await sql`
    select *
    from users`;
  // users = Result [{ name: "Walter", age: 80 }, { name: 'Murray', age: 68 }, ...]
  return c.json(users);
});

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the /api/test route on Cloudflare Pages with the nodejs_compat compatibility flag, using the per-request postgres(c.env.DATABASE_URL) setup shown. Trace the query and response lifecycle; done means the route returns the users as JSON without the hanging-Promise or “never generate a response” errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, postgresql
Domain
cloud, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.