From: Alexander Lakhin <exclusion@gmail.com>
To: Thomas Munro <thomas.munro@gmail.com>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Jelte Fennema-Nio <postgres@jeltef.nl>
Cc: Noah Misch <noah@leadboat.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Jacob Champion <jacob.champion@enterprisedb.com>
Cc: Denis Laxalde <denis.laxalde@dalibo.com>
Cc: vignesh C <vignesh21@gmail.com>
Cc: Greg Stark <stark@mit.edu>
Cc: Gregory Stark (as CFM) <stark.cfm@gmail.com>
Cc: Daniel Gustafsson <daniel@yesql.se>
Cc: Peter Eisentraut <peter@eisentraut.org>
Cc: Andres Freund <andres@anarazel.de>
Cc: Justin Pryzby <pryzby@telsasoft.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org, Etsuro Fujita <etsuro.fujita@gmail.com>
Subject: Re: [EXTERNAL] Re: Add non-blocking version of PQcancel
Date: Wed, 17 Jul 2024 22:00:00 +0300
Message-ID: <f92ce13f-cbad-769d-72df-f5b87717f375@gmail.com> (raw)
In-Reply-To: <CA+hUKG+RNLqeLug7mUwy2Ew21_oHMU+M65=Mi7Er7-nXsYwN0A@mail.gmail.com>
References: <e4d0cb33-6be5-e4d5-ae49-9eac3ff2b005@gmail.com>
<202407161508.qwzkqxsmjusg@alvherre.pgsql>
<CA+hUKG+RNLqeLug7mUwy2Ew21_oHMU+M65=Mi7Er7-nXsYwN0A@mail.gmail.com>
Hello Thomas,
17.07.2024 03:05, Thomas Munro wrote:
> On Wed, Jul 17, 2024 at 3:08 AM Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:
>> Ugh. I tried to follow what's going on in that cygwin code, but I gave
>> up pretty quickly. It depends on a mutex, but I didn't see the mutex
>> being defined or initialized anywhere.
> https://github.com/cygwin/cygwin/blob/cygwin-3.5.3/winsup/cygwin/fhandler/socket_inet.cc#L217C1-L217...
>
> Not obvious how it'd be deadlocking (?), though... it's hard to see
> how anything between LOCK_EVENTS and UNLOCK_EVENTS could escape/return
> early. (Something weird going on with signal handlers? I can't
> imagine where one would call poll() though).
I've simplified the repro to the following:
echo "
-- setup foreign server "loopback" --
CREATE TABLE t1(i int);
CREATE FOREIGN TABLE ft1 (i int) SERVER loopback OPTIONS (table_name 't1');
CREATE FOREIGN TABLE ft2 (i int) SERVER loopback OPTIONS (table_name 't1');
INSERT INTO t1 SELECT i FROM generate_series(1, 100000) g(i);
" | psql
cat << 'EOF' | psql
Select pg_sleep(10);
SET statement_timeout = '10ms';
SELECT 'SELECT count(*) FROM ft1 CROSS JOIN ft2;' FROM generate_series(1, 100)
\gexec
EOF
I've attached strace (with --mask=0x251, per [1]) to the query-cancelling
backend and got strace.log (see in attachment), while observing:
ERROR: canceling statement due to statement timeout
...
ERROR: canceling statement due to statement timeout
-- total 14 lines, then the process hanged --
-- I interrupted it several seconds later --
As far as I can see (having analyzed a number of runs), the hanging occurs
when some itimer-related activity happens before "peek_socket" in this
event sequence:
[main] postgres {pid} select_stuff::wait: res after verify 0
[main] postgres {pid} select_stuff::wait: returning 0
[main] postgres {pid} select: sel.wait returns 0
[main] postgres {pid} peek_socket: read_ready: 0, write_ready: 1, except_ready: 0
(See the last occurrence of the sequence in the log.)
[1] https://cygwin.com/cygwin-ug-net/strace.html
Best regards,
Alexander
Attachments:
[text/x-log] strace.log (348.3K, ../f92ce13f-cbad-769d-72df-f5b87717f375@gmail.com/2-strace.log)
download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: exclusion@gmail.com, thomas.munro@gmail.com, alvherre@alvh.no-ip.org, postgres@jeltef.nl, noah@leadboat.com, tgl@sss.pgh.pa.us, jacob.champion@enterprisedb.com, denis.laxalde@dalibo.com, vignesh21@gmail.com, stark@mit.edu, stark.cfm@gmail.com, daniel@yesql.se, peter@eisentraut.org, andres@anarazel.de, pryzby@telsasoft.com, robertmhaas@gmail.com, etsuro.fujita@gmail.com
Subject: Re: [EXTERNAL] Re: Add non-blocking version of PQcancel
In-Reply-To: <f92ce13f-cbad-769d-72df-f5b87717f375@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox