Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgresjs on cloudflare runs into timeout #272

Open
EzzatOmar opened this issue Mar 9, 2025 · 5 comments
Open

postgresjs on cloudflare runs into timeout #272

EzzatOmar opened this issue Mar 9, 2025 · 5 comments
Labels

Comments

@EzzatOmar
Copy link

What version of HonoX are you using?

0.1.38

What steps can reproduce the bug?

Calling postgresjs in the handler or middleware will cause a timeout problem.
I couldn't find the cause. I tried to connect to a hosted neon postgres instance.

Here are the logs
`
✘ [ERROR] write CONNECT_TIMEOUT undefined:undefined

[InspectorProxyWorker] RUNTIME INCOMING MESSAGE {
method: 'Runtime.consoleAPICalled',
params: {
type: 'error',
args: [ [Object] ],
executionContextId: 193935137,
timestamp: 1741482145606,
stackTrace: { callFrames: [Array] }
}
}
[wrangler-ProxyWorker:inf] GET / 500 Internal Server Error (30035ms)
`

I tested it just with hono -> works
In honox I replaced postgresjs with @neon/serverless and that works too.

I would like to use postgresjs because it works with cf hyperdrive (neon will not).

The minimal case is simple to reproduce.

Thanks

//routes/index.tsx
import { env } from 'hono/adapter'
import { createRoute } from 'honox/factory'
import postgres from 'postgres'

export default createRoute(async (c) => {
  const sql = postgres(env(c).DB_CONNECTION_STRING)

  const accounts = await sql`select * from accounts`

  return c.render(
    <div className="py-8 text-center">
      <div>{JSON.stringify(accounts)}</div>
    </div>
  )
})
//wrangler.jsonc
{
  "$schema": "node_modules/wrangler/config-schema.json",
  "name": "dash",
  "main": "./dist/index.js",
  // "main": "./test.ts",
  "compatibility_date": "2025-03-08",
  "compatibility_flags": [ "nodejs_compat" ],
  "assets": {
		"binding": "ASSETS",
    "directory": "./dist"
  },
  "observability": {
    "enabled": true
  }
}

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

@EzzatOmar EzzatOmar changed the title posgresjs on cloudflare runs into timeout postgresjs on cloudflare runs into timeout Mar 9, 2025
@yusukebe
Copy link
Member

yusukebe commented Mar 9, 2025

@EzzatOmar

I think you forgot to add a binding for Hyperdrive.

https://developers.cloudflare.com/hyperdrive/get-started/#4-bind-your-worker-to-hyperdrive

@EzzatOmar
Copy link
Author

I was tested it without Hyperdrive first. Idk that adding Hyperdrive makes a difference.

@yusukebe
Copy link
Member

yusukebe commented Mar 9, 2025

@EzzatOmar

Did it succeed without Hyperdrive? Anyway, you should add the Hyperdrive binding setting to the wrangle.jsonc.

@EzzatOmar
Copy link
Author

Well the connectionstring to the db is correct. Adding Hyperdrive made no difference.

It works in hono. Just in honox there is a freeze and wrangler kills the request after 30s.

@yusukebe
Copy link
Member

@EzzatOmar

Hmm. Can you share a minimal project to reproduce it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants