Client goes out of sync when pgbouncer returns ReadyForQuery for CancelRequest #141
What I observed is that sometimes clients get out of sync and start reading the result of the previous query. This doesn't happen deterministically but it's roughly this sequence:
I wrote this java console app that can reproduce the issue. However, I couldn't get it to fail with local pgbouncer and postgres. It's only reproducing when pgbouncer and postgres are on separate boxes with arround 0.3ms latency.
This is what the client, using pgjdbc, is reading off the buffer (left). You can see the
This only happening when hitting pgbouncer. It didn't repro when connecting to postgres directly.
I find the behaviour pgbouncer exhibits for
I've commented this line in pgbouncer and the problem went away.
So it is a race condition that's making pgbouncer think that the client connection is not linked as shown in this diagram.
It became more clear that this has been a problem in the past when I saw this fix. But now I realise that it only fixed the problem for a subset of cases where the clients were lucky enough to have their message received by pgbouncer. All other cases where the request has been sent by the client but not received the pgbouncer are still broken. And I think this problem cannot be fixed.
The question is, why was this behaviour introduced and what is it trying to optimise?
The text was updated successfully, but these errors were encountered: