denodrivers / postgres

PostgreSQL driver for Deno
https://denodrivers.github.io/postgres
MIT License
594 stars 95 forks source link

BrokenPipe: Broken pipe (os error 32) not handled in reconnect logic #436

Open meyer9 opened 10 months ago

meyer9 commented 10 months ago

I'm currently getting a crash sometimes when connecting to a remote database.

BrokenPipe: Broken pipe (os error 32)
    at write (ext:deno_net/01_net.js:34:21)
    at TcpConn.write (ext:deno_net/01_net.js:97:12)
    at BufWriter.flush (https://deno.land/std@0.160.0/io/buffer.ts:745:40)
    at Connection.#preparedQuery (https://deno.land/x/postgres@v0.17.0/connection/connection.ts:864:27)
    at eventLoopTick (ext:core/01_core.js:183:11)
    at async Connection.query (https://deno.land/x/postgres@v0.17.0/connection/connection.ts:951:16)
    at async Client.#executeQuery (https://deno.land/x/postgres@v0.17.0/client.ts:245:12)
    at async Client.queryObject (https://deno.land/x/postgres@v0.17.0/client.ts:433:12)
    at async Db.executeSql (file:///src/_shared/queue/db.ts:7:20)
    at async Manager.createJob (file:///src/_shared/packages/pg-boss/manager.js:490:20)

Seems like there's a check for connection errors that will reconnect, but not broken pipe errors.

tsaxking commented 7 months ago

I am getting this one too. Is there any update on it?

bombillazo commented 7 months ago

Hey, would be helpfully to check what version is being used and if it happens in the newest.

tsaxking commented 7 months ago

Sure thing, I'm using 1.17.0, but I now see there's 1.17.2, I'm switching now, but I won't be able to recreate the problem for a few hours. My deno version is 1.40.3.

BrokenPipe: Broken pipe (os error 32)
    at write (ext:deno_net/01_net.js:58:21)
    at TcpConn.write (ext:deno_net/01_net.js:130:12)
    at BufWriter.flush (https://deno.land/std@0.160.0/io/buffer.ts:745:40)
    at Connection.#preparedQuery (https://deno.land/x/postgres@v0.17.0/connection/connection.ts:864:27)
    at eventLoopTick (ext:core/01_core.js:64:7)
    at async Connection.query (https://deno.land/x/postgres@v0.17.0/connection/connection.ts:951:16)
    at async Client.#executeQuery (https://deno.land/x/postgres@v0.17.0/client.ts:245:12)
    at async Client.queryObject (https://deno.land/x/postgres@v0.17.0/client.ts:433:12)
    at async file:///.../master/server/utilities/databases.ts:738:32
    at async attemptAsync (file:///.../master/shared/check.ts:134:23) {
  name: "BrokenPipe",
  code: "EPIPE"
}
dylanpyle commented 2 months ago

Same here, using 0.19.2

mahdiyari commented 3 days ago

Latest versions of deno and postgres as of writing this comment. Issue is still there. It happens with transactions that take too long.

mahdiyari commented 3 days ago

I found the actual reason behind it. Whenever you create a transaction and then leave that transaction idle longer than idle_in_transaction_session_timeout, Posgresql server will close the session. And that causes the above error.