I notice that if an ERROR occurs during ProcessCatchupEvent() then the
messages back to client get out of sync with each other. I've inserted
an optional error into ProcessCatchupEvent() to show what happens
(attached).
> postgres=# begin;
> BEGIN
> postgres=# d;
> ERROR: an error occurred while processing catchup event
> postgres=# commit;
> ERROR: syntax error at or near "d"
> LINE 1: commit;
> ^
> postgres=# commit;
> ROLLBACK
> postgres=# begin;
> WARNING: there is no transaction in progress
> COMMIT
Notice how "commit" has been issued twice... and that there is no "d" in
commit. LOL, but :-(
This issue happens to be exactly the same as the one I have while trying
to make SIGINT cancel an idle-in-transaction session. I was looking at
the catchup interrupt to try to learn more about this area of code, only
to find the same problem exists there also. Perhaps there is no
possibility of an ERROR happening during catchup processing, but looking
at the rest of ProcessCatchupEvent(), I doubt it.
(The attached patch allows behaviour to be turned on/off using
synchronous_commit but that has *nothing* to do with this issue and was
chosen to avoid inventing a new switch based on what was in miscadmin.h)
It looks to me that generating a single error message while idle causes
the server to provide ErrorResponse, which the client assumes is the end
of the processing of that statement as defined in FE/BE protocol. Yet
server continues processing anyway and gives second response later.
This also behaves differently on some tests, generating an infinite loop
of messages to the log and on the psql client like this:
ERROR: an error occurred while processing catchup event
message type 0x5a arrived from server while idle
ERROR: an error occurred while processing catchup event
message type 0x5a arrived from server while idle
...
having used over 8 minutes of CPU as I post this, with 1 CPU at 100%,
even after the client disconnects.
Thoughts, go-look-theres or other comments welcome.
--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support