-
Notifications
You must be signed in to change notification settings - Fork 73
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
Using the postgres-js driver to access a database works correctly on the first request, but fails with the following errors on every other subsequent request.
X [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 / 500 Internal Server Error (9ms)
X [ERROR] Uncaught (in response) Error: The script will never generate a response.
X [ERROR] Uncaught (async) Error: Promise will never complete.
Steps to reproduce
- Create an opennext project using
npm create cloudflare@latest -- my-next-app --framework=next --platform=workers
- Install postgres
npm install --save postgres
- Create a database script. Making sure to have the
DATABASE_URL
defined to a valid pg database:
import postgres from "postgres";
const connectionString = process.env.DATABASE_URL;
export const client = postgres(connectionString!);
- Replace the contents of
app/page.tsx
with the following. Change the db query to match a test table in your databse.
import { client } from "@/db/db";
export const dynamic = "force-dynamic";
export default async function Home() {
const result = await client`SELECT * FROM users;`;
return <h1>{JSON.stringify(result)}</h1>;
}
- Run the worker
npm run preview
- Open the page in the browser, refresh the page to trigger the error.
Expected behavior
The request should consistently resolve, fetching from the database and return the data.
An equivalent request on a bare-bones typsecript cloudflare worker project resolves the same request without issues.
@opennextjs/cloudflare version
~1.0.0-beta.0 || ^1.0.0
Wrangler version
^4.8.0
next info output
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024
Available memory (MB): 31983
Available CPU cores: 20
Binaries:
Node: 22.14.0
npm: 10.9.2
Yarn: N/A
pnpm: 10.8.0
Relevant Packages:
next: 15.2.4 // Latest available version is detected (15.2.4).
eslint-config-next: 15.2.4
react: 19.1.0
react-dom: 19.1.0
typescript: 5.8.3
Next.js Config:
output: N/A
Additional context
No response
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Type
Projects
Status
Done