diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2019-11-24 14:42:59 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2019-11-24 14:42:59 -0500 |
commit | 7900269724424b6deca516eba3dd8e4bf6621bea (patch) | |
tree | efdfe33e5df1003d4618ea5ffd984ea3592f2dcd /src/backend/tcop/postgres.c | |
parent | 8b7ae5a82d04312672c919ecea3c30b1ec7faaf2 (diff) | |
download | postgresql-7900269724424b6deca516eba3dd8e4bf6621bea.tar.gz postgresql-7900269724424b6deca516eba3dd8e4bf6621bea.zip |
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
Diffstat (limited to 'src/backend/tcop/postgres.c')
-rw-r--r-- | src/backend/tcop/postgres.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index d7a72c0766b..3b85e48333d 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -4194,7 +4194,18 @@ PostgresMain(int argc, char *argv[], } else { + /* Send out notify signals and transmit self-notifies */ ProcessCompletedNotifies(); + + /* + * Also process incoming notifies, if any. This is mostly to + * ensure stable behavior in tests: if any notifies were + * received during the just-finished transaction, they'll be + * seen by the client before ReadyForQuery is. + */ + if (notifyInterruptPending) + ProcessNotifyInterrupt(); + pgstat_report_stat(false); set_ps_display("idle", false); |