Re: Add client connection check during the execution of the query
Thomas Munro <thomas.munro@gmail.com>
From: Thomas Munro <thomas.munro@gmail.com>
To: Zhihong Yu <zyu@yugabyte.com>
Cc: Tatsuo Ishii <ishii@sraoss.co.jp>, Tom Lane <tgl@sss.pgh.pa.us>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2021-03-23T21:53:45Z
Lists: pgsql-hackers
Attachments
- v7-0001-Detect-dropped-connections-while-running-queries.patch (text/x-patch) patch v7-0001
On Tue, Mar 23, 2021 at 11:47 PM Thomas Munro <thomas.munro@gmail.com> wrote: > That leaves the thorny problem Tom mentioned at the top of this > thread[1]: this socket-level approach can be fooled by an 'X' sitting > in the socket buffer, if a client that did PQsendQuery() and then > PQfinish(). Or perhaps even by SSL messages invisible to our protocol > level. That can surely only be addressed by moving the 'peeking' one > level up the protocol stack. I've attached a WIP attemp to do that, > on top of the other patch. Lookahead happens in our receive buffer, > not the kernel's socket buffer. After sleeping on this, I'm still not seeing any problem with this approach. Sanity checks welcome. Of course that function should be called something like pq_peekmessage() -- done. I think this patch addresses all critiques leveled at the earlier versions, and I've tested this with SSL and non-SSL connections, by killing psql while a query runs, and using a client that calls PQfinish() after starting a query, and in an earlier version I did yank-the-cable testing, having set up TCP keepalive to make that last case work.
Commits
-
Add WL_SOCKET_CLOSED for socket shutdown events.
- 50e570a59e7f 15.0 landed
-
Use WL_SOCKET_CLOSED for client_connection_check_interval.
- cba5b994c990 15.0 landed
-
Detect POLLHUP/POLLRDHUP while running queries.
- c30f54ad732c 14.0 landed
-
Improve timeout.c's handling of repeated timeout set/cancel.
- 09cf1d522676 14.0 cited