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 1wgqnC-006SEE-2F for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jul 2026 21:23:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wgqnA-0035I5-1Q for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jul 2026 21:23:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wgqnA-0035Hx-0U for pgsql-hackers@lists.postgresql.org; Mon, 06 Jul 2026 21:23:52 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wgqn8-00000001uPh-1YmI for pgsql-hackers@postgresql.org; Mon, 06 Jul 2026 21:23:51 +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 4gvHR36fphz49Q4p; Tue, 07 Jul 2026 00:23:43 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1783373024; 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=z6A3QZuZBKR4uQfNzd3XYIiP8h6eStv6e9O33w8t6HU=; b=wG35V6cILW8LOD9UozGABry3pA9cPqbAN+I7AtxrT+MskY++rVJ8s2HoIdG+wY6BV4AUfz VvPJodsfSmcK9PqnaUuYCIVGMyB5YjhHHpSlT5BX9O33CuA2lcgw0kKLPWE8xLQUMduNaJ +ikeaimp4CDPi31cF2sebCGKUsec79vFQFjL44QD/OVpQKXp0dHi2RtyKZdKCjxIjPDT9h LmkK7BSzVz44IuEsDXhcAJnUhkthvJu7ij6la7gO6GVpl+nz/vhrk9DuBDrPgd7zOHZys+ uqKDyvLOJcH/r6KcU49rDExZU8DnvRViVzQ6Z0S7EQUtMwHReGcgZz21oe4W6Q== ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=lahtoruutu; cv=none; t=1783373024; b=Bb4lLTcTeAGz/kuiRrbCVI8qrgSfb5vQvkTDzWAG9XsX1Spo4/VCyKpu0DIkJYlfRcmUFf RgDDlJS4jQpiDg5+bWBjdGnkNwnHlOSNctvn14E7Q8kwHJkSppJFfwrel3ovslwQIhixuO wHXvJzg1XTiRK6cXiLMd/cGjy9gKW++bMeZ7nmy03f9AYNg1ueAH1by2OnE1BYU8iKh5Y+ QEnjfaFgxcrsO9r2PK6emgGAaAXy1YeGW2+DpnlNlKHrnHhFnRLJhxUrBvIn7HoJDrloJ9 Y/+jhKz+gCNtT7LdktdbPEapU8DNtmLzA7N59doFuodA3qClws7GK9CgAiuQLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1783373024; 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=z6A3QZuZBKR4uQfNzd3XYIiP8h6eStv6e9O33w8t6HU=; b=au8YgCXumZ1FcyyN4EjRVbHek80RN4UKxS7V0j0/r8YsK8fWbes66+xB6g6v1JTC4kvHXU Tx997+/dKHbgO154Zbxlgl0YdAOAINFwmFlUkbUwzOjeBJ7ylrCfImlxLzG5FqoMXSWQs0 /Bey5OWC7GXHuZnK30cwl0SSVtpjQL0uvd4l0e44LLzWzrhWp1n1ZR48RwwyLNQf7bpqPs DeYz2fSn6Owbb18EqxwxwhOPL+uTS9KbdiqkZd7p+RE3Rro9jzQOfYlA8cLTilCniNzZzG +riWk5RaouQuYenlLZ+hkz/QtlWAlOuYRbqSIzZXOzqfND9S8mTqexr6r2MZuw== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi Message-ID: <400c93d2-0b81-4a0b-ac60-0fd6512d5b5d@iki.fi> Date: Tue, 7 Jul 2026 00:23:42 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Can we get rid of TerminateThread() in pg_dump? From: Heikki Linnakangas To: Thomas Munro , Jelte Fennema-Nio Cc: Bryan Green , pgsql-hackers , Tom Lane , Kyotaro Horiguchi References: <56821e0d-bfd5-4619-b13f-12e28c78289b@iki.fi> <5e4a28ec-d5e1-4817-889c-b8aefe5f48ed@iki.fi> Content-Language: en-US In-Reply-To: <5e4a28ec-d5e1-4817-889c-b8aefe5f48ed@iki.fi> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 07/07/2026 00:11, Heikki Linnakangas wrote: > On 05/07/2026 08:03, Thomas Munro wrote: >> On Sat, Jul 4, 2026 at 11:15 PM Jelte Fennema-Nio >> wrote: >>> On Sat, 4 Jul 2026 at 02:51, Thomas Munro >>> wrote: >>>> We don't actually care about the threads >>>> themselves, and it doesn't seem that great if we have to introduce an >>>> IPC ping-pong of some kind with each thread. >>> >>> Agreed. But I do agree with Heikki that swapping out stderr seems pretty >>> hacky. At the very least because now the main thread cannot write to >>> stderr either anymore (which is why you removed the "terminated by user" >>> write I guess). >>> >>> How about instead we do something like the attached? >> >> That's definitely nicer, if we know that all potential error logging >> caused by cancellation happens in a context that can check the flag. > > +1, much nicer! > >> I didn't even look into that, because I was deliberately trying to >> avoid needing atomics from here, because I need this to work on Unix >> too, and I didn't want to open too many cans of worms at the same >> time.  Hence the appeal of a simple async-signal-safe system call that >> has the right concurrency properties already and works also on Windows >> without a separate code path.  But... reaching for the can opener... >> >> 1. If we're ready to drop VS < 2022 and GCC < 4.9, we could just use >> directly in frontend code (independently of the project >> to use it in the backend). >> 2. If we're not ready yet we could make "port/atomics.h" or selected >> parts of it frontend-allowed. >> 3. Maybe all we really need for this case is memory barriers, and we >> could move those out to a frontend-allowed header. > > To be honest, I didn't realize we didn't allow "port/atomics.h" in > frontend code. I think spinlock-simulated 64-bit atomics is the only > thing that wouldn't just work. In this case, though, I think all we need is a "volatile sigatomic_t" flag. Sending the query cancellation over the network surely acts as a full compiler and memory barrier in the cancelling thread. And similarly receiving the error message from the network acts as a full barrier in the other threads that might receive the cancellation error from the backend. - Heikki