Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wh79p-0000m5-2M for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jul 2026 14:52:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wh79n-0018uo-0L for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jul 2026 14:52:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wh79m-0018ue-2Q for pgsql-hackers@lists.postgresql.org; Tue, 07 Jul 2026 14:52:19 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wh79k-000000003E9-0saB for pgsql-hackers@lists.postgresql.org; Tue, 07 Jul 2026 14:52:18 +0000 Received: from [10.0.2.15] (unknown [130.41.208.2]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4gvkhs6n6pz49Px6; Tue, 07 Jul 2026 17:52:13 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1783435934; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KitgtOkpOvoIh42b7fStcyyQ39HMmjrypmwejp1L7Vw=; b=oxOAefaGpGUIP+fcPuPwkku0qTcNO8pWoQjr5fT/VTsa+hrBoQnrpjjfhYcab1wrTYgWI4 3KUc5fkb0WxCBdodmQRBpMSF3XCQkOrgHLSpZVPXBS3VEgn5Q2o0eo9YNUBR1WU8Mo9Q+o V++g/V/IePnwnbgpSCvl4LM8IZK5hTXiGdHxCPO592TnMqE293kQeFLFx1mDsycE4Ab2p8 pq973daDO+8JbT3U+NV42g+y+n0BvS63f+dyBK7EU8mSIQSrtgrbvh/iJblcf8OAZqdpgt 07ebzbO/aEjoi8mAwCy10kABInOdi9uXJS59vHQl+WC5XFxtEEQB6LNnxsZcPg== ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=lahtoruutu; cv=none; t=1783435934; b=kNantxn/zi9pRZnTFu0hlf5WzTpilGycoe4MFokjbvf2yQYHa3EhjK7CQjzb8tquttNmhr Y7QuFZJCp6C6BU7i5Y6A7yL4KN5W1FuywWEIiWHAPKy+mU05w1l/1YGJoHI81EMtyr76iE jQwUV4VdQA680GQeDUeCoCuntjs3QmF97rFf4aThJgz5nLyd4LPJbW4OMcuvuOFco9qujI 9X9CW05yu09SdCezGMuyC8uK3V+qmZXNB10rSX5TkzRInSjV0arxqdQzhSWrS6DtpakBoA zB659PWgBovC+BFLnapbDtO1GE2cKlu39CA1V/U3wFxWWkEkKhRwZgrMzQF30g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1783435934; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KitgtOkpOvoIh42b7fStcyyQ39HMmjrypmwejp1L7Vw=; b=sWjl2mMdHDqw4lJV1PHOkG6QZI4NHL+4/h7lyev8RCRy5HVVxA0EKpbtwX3noj/r1x4YGl FrOR3fP/zcnitwyQX9gUuMWv6CC9oYlgHjYSYnx17DGqLk9YIi+Ui/wembeunoBDj5YfVR X40pi+SAB1SLaQZEWr4TqYCNqbI0ciNWylIXyt5X7uUl/qCRPSAgxZPc0UZEquuqSX+0nG uHutNoENYkTp0Cjv49lhXlFKLb7k14/05Aah+c7PmM3p1euoJp4Or1o2OefSsSrS6Ta8+z orsH3/oAJv5bLtL/wLJCnYgvUzHsFRyFaiB85jZSWS29kgrydE35UUBmroMvGQ== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi Message-ID: Date: Tue, 7 Jul 2026 17:52:12 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Don't use the deprecated and insecure PQcancel in our frontend tools anymore To: Jelte Fennema-Nio Cc: PostgreSQL Hackers , Alvaro Herrera , Jacob Champion References: <88dfe280-ba29-4943-95b8-63abc9f3f771@iki.fi> <9d7ba3ac-d660-483e-8f68-9096a2464e90@iki.fi> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 07/07/2026 10:54, Jelte Fennema-Nio wrote: > On Tue Jul 7, 2026 at 12:12 AM CEST, Heikki Linnakangas wrote: >> This relies on the signal to interrupt select(), but I'm afraid that's >> not guaranteed on all platforms. Also, there's a race condition if the >> signal arrives *just* before you call select(). That's what the "self- >> pipe hack" is for, see comments at waiteventset.c. > > Ugh yes you're right. The comment above that block told me otherwise and > I didn't question it. Attached is a new version that improves the > comment and starts using the same 1 second poll on all platforms. Yeah, I guess that works.. But It's a little unsatisfactory to have to poll, where we didn't poll before. I started to go down the rabbit hole, here are the options I can think of: a) switch to pselect() where available, fall back to select() with timeout. We don't currently use pselect() anywhere, so this needs a new configure check. b) switch to ppoll() where available, fall back to select() with timeout. ppoll() is already used in pgbench, and is a better interface in general. However, it's different from select(), so the fallback code would differ more. c) switch to ppoll() where available, fall back to poll() with timeout. Use WaitForMultipleObjectsEx() on Windows (it has neither ppoll() nor poll()). The fallback would look more similar to the main code path than with b), but the Windows implementation would be even more different. We could actually eliminate the polling in Windows too, if we added an Event object for the cancellation too. d) like c), but write a helper function to implement poll()/ppoll() on Windows using WaitForMultipleObjectsEx(). Could be used in more places then. d) seems like the nicest option in the long run, but takes a little effort, and I don't have a Windows system to test on currently. While poking around, I noticed that we actually already have a win32 implementation of select() using WaitForMultipleObjectsEx(), in src/backend/port/win32/socket.c. But AFAICS it's not used anywhere. Other prior art: In libpq we have PQsocketPoll(), which uses poll() or select(), but it only operates on a single socket. I wonder if we could bump up our minimum portability requirements, and e.g. require ppoll() on all all non-Windows systems. - Heikki