Stabilize NOTIFY behavior by transmitting notifies before ReadyForQuery.
authorTom Lane
Sun, 24 Nov 2019 19:42:59 +0000 (14:42 -0500)
committerTom Lane
Sun, 24 Nov 2019 19:42:59 +0000 (14:42 -0500)
commitc47f498c93f9ebbb44cd03cf82f817da15761350
tree9667b2c12b7ccd8bc3094734cea6ca0d5aa3c708
parent7d4c3118137a37dddcefe28145a3a2e4bccf59fd
Stabilize NOTIFY behavior by transmitting notifies before ReadyForQuery.

This patch ensures that, if any notify messages were received during
a just-finished transaction, they get sent to the frontend just before
not just after the ReadyForQuery message.  With libpq and other client
libraries that act similarly, this guarantees that the client will see
the notify messages as available as soon as it thinks the transaction
is done.

This probably makes no difference in practice, since in realistic
use-cases the application would have to cope with asynchronous
arrival of notify events anyhow.  However, it makes it a lot easier
to build cross-session-notify test cases with stable behavior.
I'm a bit surprised now that we've not seen any buildfarm instability
with the test cases added by commit b10f40bf0.  Tests that I intend
to add in an upcoming bug fix are definitely unstable without this.

Back-patch to 9.6, which is as far back as we can do NOTIFY testing
with the isolationtester infrastructure.

Discussion: https://postgr.es/m/13881.1574557302@sss.pgh.pa.us
src/backend/commands/async.c
src/backend/tcop/postgres.c