pgconn icon indicating copy to clipboard operation
pgconn copied to clipboard

Reading ERROR before connection reset

Open x4m opened this issue 4 years ago • 3 comments

Hi!

When someone is using a connection pooler like Odyssey or PgBouncer they might want to enable pool_timeout (Odyssey) or query_wait_timeout(Bouncer) feature. In this case, the client waiting for some time for a free server connection might get ErrorResponse from the pooler followed by client disconnection. Odyssey user will get "read tcp [2a02:6b8:0:2807:70d5:dc6a:5f2c:3882]:50336->[2a02:6b8:c1e:222f:0:1589:7844:129b]:6432: read: connection reset by peer". PgBouncer users will get simply "Unexpected EOF".

I think pooler has no change to pretend that Be\Fe sync persists. If we can fix this on the pooler side I'd be happy to do so.

Can we make receiveMessage() return the first ErrorResponse it encounters even if MRR is not closed yet, but the connection is broken?

Many thanks for maintaining such useful lib!

x4m avatar Jan 28 '21 12:01 x4m

I'm not sure I understand the issue.

The pooler sends an error and then closes the the connection? What level of error is it? I would expect it to be FATAL and that should be handled propoerly.

Also, I'm not sure I understand what you want the client to do differently.

jackc avatar Jan 30 '21 17:01 jackc

OK, I'll try to fix it on poolers' side. https://github.com/yandex/odyssey/pull/271 https://github.com/pgbouncer/pgbouncer/pull/564

If disconnection is preceded by any error, driver could save this error to show to user. See #64

x4m avatar Jan 31 '21 09:01 x4m

The fix was merged to both poolers. But I still think It may make sense to prefer to return Postgres error over network error.

x4m avatar Jan 10 '22 10:01 x4m