Fix bogus when-to-deregister-from-listener-array logic.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 13 Feb 2013 17:48:15 +0000 (12:48 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 13 Feb 2013 17:48:15 +0000 (12:48 -0500)
commit52c889ea4f7696157fde4b74ae62fbe014d06087
treeb502e9ad8bae27a8f8d1a4473e6854b6dc145d46
parentbffee6c52c7ae618a7f06da023bfdb66deb0bdb1
Fix bogus when-to-deregister-from-listener-array logic.

Since a backend adds itself to the global listener array during
Exec_ListenPreCommit, it's inappropriate for it to remove itself during
Exec_UnlistenCommit or Exec_UnlistenAllCommit --- that leads to failure
when committing a transaction that did UNLISTEN then LISTEN, since we end
up not registered though we should be.  (This leads to missing later
notifications, or to Assert failures in assert-enabled builds.)  Instead
deal with deregistering at the bottom of AtCommit_Notify, when we know the
final state of the listenChannels list.

Also, simplify the representation of registration status by replacing the
transient backendHasExecutedInitialListen flag with an amRegisteredListener
flag.

Per report from Greg Sabino Mullane.  Back-patch to 9.0, where the problem
was introduced during the LISTEN/NOTIFY rewrite.
src/backend/commands/async.c