Re: [EXTERNAL] Re: PQcancel does not use tcp_user_timeout, connect_timeout and keepalive settings
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jelte Fennema <Jelte.Fennema@microsoft.com>
Cc: Andres Freund <andres@anarazel.de>,
Fujii Masao <masao.fujii@oss.nttdata.com>,
Zhihong Yu <zyu@yugabyte.com>,
"pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2022-01-11T23:27:21Z
Lists: pgsql-hackers
Attachments
- v2-0001-Refactor-to-remove-internal_cancel-helper.patch (text/x-diff) patch v2-0001
- v2-0002-Use-timeout-socket-options-for-cancel-connections.patch (text/x-diff) patch v2-0002
Jelte Fennema <Jelte.Fennema@microsoft.com> writes: > Attached are 3 patches that address the feedback from Andres about code duplication > and splitting up commits. I completely removed internal_cancel now, since it only had > one caller at this point. Here's some cleaned-up versions of 0001 and 0002. I have not bothered with 0003 because I for one will not be convinced to commit it. The risk-vs-reward ratio looks far too high on that, and it's not obvious why 0002 doesn't already solve whatever problem there is. A couple of notes: 0001 introduces malloc/free into PQrequestCancel, which promotes it from being "probably unsafe in a signal handler" to "definitely unsafe in a signal handler". Before, maybe you could have gotten away with it if you were sure the PGconn object was idle, but now it's no-go for sure. I don't have a big problem with that, given that it's been deprecated for decades, but I made the warning text in libpq.sgml a little stronger. As for 0002, I don't see a really good reason why we shouldn't try to do it on Windows too. If connect() will work, then it seems likely that setsockopt() and WSAIOCtl() will too. Moreover, note that at least in our own programs, PQcancel doesn't *really* run in a signal handler on Windows: see commentary in src/fe_utils/cancel.c. (The fact that we now have test coverage for PQcancel makes me a lot more willing to try this than I might otherwise be. Will be interested to see the cfbot's results.) Also, I was somewhat surprised while working on this to realize that PQconnectPoll doesn't call setTCPUserTimeout if keepalives are disabled per useKeepalives(). I made PQcancel act the same, but I wonder if that was intentional or a bug. I'd personally have thought that those settings were independent. regards, tom lane
Commits
-
Make PQcancel use the PGconn's tcp_user_timeout and keepalives settings.
- 5987feb70b5b 15.0 landed
-
Avoid calling gettext() in signal handlers.
- d18ec312f9f3 13.6 landed
- 92e6c1c9be15 11.15 landed
- 6d1a854c157e 12.10 landed
- 62bfa554b285 10.20 landed
- 4e8726566e4d 14.2 landed
- 2131c049d338 15.0 landed
-
Avoid calling strerror[_r] in PQcancel().
- 9d66c43eb4c8 10.20 landed
- f3f467b8f69b 15.0 landed
- f27af7b880de 13.6 landed
- 8b107467c632 11.15 landed
- 38f099ef935b 12.10 landed
- 050949877004 14.2 landed