From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Greg Sabino Mullane <greg(at)endpoint(dot)com> |
Cc: | pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: Unlisten / listen in a transaction failure |
Date: | 2013-02-13 16:16:59 |
Message-ID: | 19305.1360772219@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
Greg Sabino Mullane <greg(at)endpoint(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | autarch | 2013-02-13 20:22:43 | BUG #7873: pg_restore --clean tries to drop tables that don't exist |
Previous Message | Greg Sabino Mullane | 2013-02-13 14:55:22 | Unlisten / listen in a transaction failure |