pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Greg Sabino Mullane <greg@endpoint.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: Unlisten / listen in a transaction failure
Date: Wed, 13 Feb 2013 11:16:59 -0500
Message-ID: <19305.1360772219@sss.pgh.pa.us> (raw)
In-Reply-To: <20130213145522.GI23404@broken.home>
References: <20130213145522.GI23404@broken.home>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Greg Sabino Mullane <greg@endpoint.com> writes:
> I came across some unusual behavior with listen. Basically, if you 
> unlisten and listen inside of a transaction, new notices are not 
> picked up right away - but they will show up if you send yourself 
> a notice. It also works as expected if you unlisten, commit, and 
> then re-listen. Tested on 9.1 and 9.2. Demo psql script:

Huh.  If you run this in an assert-enabled build, it gets an assert
failure:

regression=# listen abc;
LISTEN
regression=# notify abc;
NOTIFY
Asynchronous notification "abc" received from server process with PID 19048.
regression=# begin; unlisten *; listen abc; commit;
BEGIN
UNLISTEN
LISTEN
COMMIT
regression=# notify abc;
The connection to the server was lost. Attempting reset: Failed.

The Assert is

TRAP: FailedAssertion("!(MyProcPid == (asyncQueueControl->backend[MyBackendId].pid))", File: "async.c", Line: 1821)

which shows that we aren't actually registered in the global array of
listeners, even though we think we should be.

I think the problem is that we do Exec_ListenPreCommit, then
Exec_UnlistenAllCommit, then Exec_ListenCommit --- and the second
of these undoes our registration as a listener.  That needs rethinking.
Looking at it, the backendHasExecutedInitialListen flag seems pretty
badly thought out too.  It looks to me like we'd be better off with a
flag defined like "amRegisteredListener" that tracks whether we're
currently in the array or not, and during AtCommit_Notify() we shouldn't
deregister as a listener until we've scanned all the pending actions and
know whether we are ending in a no-listens state or not.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (2+ messages)

Message-ID: <19305.1360772219@sss.pgh.pa.us>
Permalink:  ../19305.1360772219@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/19305.1360772219@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, greg@endpoint.com
  Subject: Re: Unlisten / listen in a transaction failure
  In-Reply-To: <19305.1360772219@sss.pgh.pa.us>
  References: <20130213145522.GI23404@broken.home> <19305.1360772219@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox