Re: NOTIFY does not work as expected
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andrey <parihaaraka@gmail.com>
Cc: Jeff Janes <jeff.janes@gmail.com>, andres@anarazel.de,
Pg Bugs <pgsql-bugs@postgresql.org>
Date: 2018-10-18T22:39:34Z
Lists: pgsql-bugs
Attachments
- 0001-server-notify-fix.patch (text/x-diff) patch 0001
- 0002-client-notify-fix.patch (text/x-diff) patch 0002
Andrey <parihaaraka@gmail.com> writes: > Hello. I beg your pardon, but the problem is still in 10.5. May we expect > it to be fixed in 11? Nope :-(. However, I got around to looking at this problem, and I concur with Jeff's diagnosis: the code around ProcessClientReadInterrupt is buggy because it does not account for the possibility that the process latch was cleared some time ago while unhandled interrupt-pending flags remain set. There are some other issues too: 1. ProcessClientWriteInterrupt has the same problem. 2. I don't believe the "blocked" vs "not-blocked" distinction one bit. At best, it creates race-condition-like changes in behavior depending on exactly when a signal arrives vs when data arrives or is sent. At worst, I think it creates the same problem it's purporting to solve, ie failure to respond to ProcDiePending at all. I think the before/during/after calls to ProcessClientXXXInterrupt should just all behave the same and always be willing to execute ProcDiePending. 3. We've got bugs on the client side too. The documentation is pretty clear that libpq users ought to call PQconsumeInput before PQnotifies, but psql had not read the manual at all. Also, most callers were calling PQconsumeInput only once and then looping on PQnotifies, which assumes not-very-safely that we could only see at most one TCP packet worth of notify messages at a time. That's even less safe now that we have "payload" strings than it was before. So we ought to adjust the code and documentation to recommend doing another PQconsumeInput inside the loop. (Congratulations to dblink for getting this right.) In short, I think we need something like the attached. With these patches, psql consistently reports the notification promptly (for me anyway). regards, tom lane
Commits
-
Client-side fixes for delayed NOTIFY receipt.
- ecc59e31a81e 10.6 landed
- d30d27a52818 11.1 landed
- ac3be116a798 9.5.15 landed
- 4247db62522f 12.0 landed
- 34aad21cbf03 9.6.11 landed
-
Server-side fix for delayed NOTIFY and SIGTERM processing.
- f4941666afc6 9.5.15 landed
- cbab94077e12 9.6.11 landed
- 7aaeb7b45ac7 11.1 landed
- 3bdef6d21131 10.6 landed
- 2ddb9149d14d 12.0 landed
-
Introduce and use infrastructure for interrupt processing during client reads.
- 4f85fde8eb86 9.5.0 cited