porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare
The Unlicense
7.04k stars 257 forks source link

Timeout issue when using with Bun #817

Closed lnlife closed 3 months ago

lnlife commented 4 months ago

I created a simple http server with http.createServer, and query database when requests come: let rows = await sql.unsafe(query, args, { prepare: true })

After starting the server it works fine at beginning. But if do not send request after a while (maybe 1+ hour), then send request again, got query timeout:

22 |       errno: x,
23 |       address: options.path || host
24 |     }, options.path ? {} : { port: port }
25 |   )
26 |   Error.captureStackTrace(error, connection)
             ^
error: write CONNECT_TIMEOUT localhost:5432
 code: "CONNECT_TIMEOUT"

      at connection (/home/test/node_modules/postgres/src/errors.js:26:9)
      at connectTimedOut (/home/test/node_modules/postgres/src/connection.js:433:14)
      at done (/home/test/node_modules/postgres/src/connection.js:1035:12)

This issue only occurs on Bun, not on Node.(I've tested both)

Nickhoyer commented 4 months ago

I have the same issue. Seems to be fixed in November in #738 but there hasn't been any releases to npm.

@porsager is there any reason there hasn't been any releases to npm?

amjed-ali-k commented 4 months ago

@porsager Kindly release new version to npm. or a beta version.

porsager commented 4 months ago

You can install from github by using porsager/postgres#commithash

porsager commented 4 months ago

I have the same issue. Seems to be fixed in November in #738 but there hasn't been any releases to npm.

@porsager is there any reason there hasn't been any releases to npm?

No other reason than limited time on my end 😔

porsager commented 3 months ago

v3.4.4 released

evelant commented 3 months ago

@porsager a new bug may have been introduced, now when calling postgres.end({timeout: 30}) it never completes until the timeout on my Bun app

porsager commented 3 months ago

please test with node and let me know if there's an issue. If there is only an issue with bun you need to file it in the bun repo.

evelant commented 3 months ago

@porsager I'll see if I can reproduce with node, but at least on Bun this is definitely a regression between 3.4.3 and 3.4.4. I rolled back to 3.4.3 and the connection terminates instantly instead of waiting for the timeout.

porsager commented 3 months ago

right, the "workaround" solving the previous bun error probably shouldn't have been made, and instead solved in bun instead 😅

So from now on I'm not taking bug reports from bun anymore 😜 Bun has stated "many" times, that things working in node should work in bun, and bug reports should go to the bun repo then.

amjed-ali-k commented 3 months ago

@porsager seems that "workaround" might be the issue. getting this so frequently now.

Bun 1.1.0 | PostgresJs 3.4.4 | drizzle-orm 0.30.6

image

porsager commented 3 months ago

You should go thumb up that issue on bun ;) https://github.com/oven-sh/bun/issues/7325

Jarred-Sumner commented 2 months ago

The fix for this will land in Bun v1.1.7, which we aim to release in a few hours

wiesys commented 1 month ago

Hmm... the issue with not properly closing the connection for me is present even in Bun v1.1.8. Does it work for you @evelant? 🤔

evelant commented 1 month ago

I haven't tried it yet, sorry

wiesys commented 1 month ago

No worries, in case you have time, you could check so I can be sure that I'm not the only one 🙂

dahlia commented 1 month ago

@wiesys I'm using Postgres.js 3.4.4 on Bun 1.1.8 and the issue is still present.

amjed-ali-k commented 1 month ago

The fix for this will land in Bun v1.1.7, which we aim to release in a few hours

@Jarred-Sumner Its still there. https://github.com/oven-sh/bun/issues/7325#issuecomment-2123535963