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 1wgF1I-0062z6-1I for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Jul 2026 05:03:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wgF1F-00BPYF-02 for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Jul 2026 05:03:53 +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 1wgF1E-00BPY7-2A for pgsql-hackers@lists.postgresql.org; Sun, 05 Jul 2026 05:03:52 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wgF1B-00000001oZD-3gIe for pgsql-hackers@postgresql.org; Sun, 05 Jul 2026 05:03:51 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2caa0551d8bso5868865ad.2 for ; Sat, 04 Jul 2026 22:03:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783227827; cv=none; d=google.com; s=arc-20260327; b=KiWazspdWzk1LxfdgugqkVgsyRnnruWxKFFu1IF2qL6UjHT7JS9vJlquug7gt027bG /tB35GGO0tQWLtUBS9+jA7F4wHrQxeKSA+Qc/5X1ldBkefeQm3NqlezSxVAkS6Vk/glO tNO9hzO9XCGUzduSAOrFBpJcldhoqgAELOpZuiqSNgL5pBlmyAgGf8QW9RzpgPt9VYPb lNObfYEuj6ba9Pbtbs9tgj5TtAvtJn7ZQxIB+0HZH+96Osm8nN94AkuBaChHnm03hR+l 0WwFjTDHDt2CziQI+HV4mc7T/RElffyGHM6dpCKWCXQmbVwbNUxQh3ROWwGjeQt++zta Qf6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=BgEKd6Mh2oZg30kt6Uz0XcEr3ImU0ZF3LM46rmQ/KpE=; fh=8zKccQULHFXTljflL9IVQSvfN2aVZFWSz7Hrq/6DEX8=; b=TTr+18uZpCGzh8Qm5KsMUm+RRfy1R2reJdVsjGLq0ry2IG9xLfV/vX5baRs1qY9uEk 4yUg4aJfu+2ZreBpjCQ6IzexoV41T0cct3NoLRAZ7Qgo7vvyHLDl+kDbhLndtXzoxkJS lV+aF0BOhXJqPdzFKf9XB680/1hBtZoL3QxFupY2ytltviV/JqDY9txgQan/VKsc7K3S 4LU2iRP9mw/GnkabPfJvbzZEK8jMl1gn+gi7HFP5GK1jhdimw3gIXj6izaqrXwg4z04R b9eiMA4cdNAouxqa3Mr6T+KgDvgJAGZBW6lt/iF/DYCzttKCLJUpxMv8V06D8b5FSqV6 Kt7Q==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783227827; x=1783832627; darn=postgresql.org; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:from:to:cc:subject :date:message-id:reply-to:content-type; bh=BgEKd6Mh2oZg30kt6Uz0XcEr3ImU0ZF3LM46rmQ/KpE=; b=eDmiwjKFl97IPc1BYuXJmdleE7gKTvpr8++VaQln070tbjSSErkaeL5lOCIgwHHGJz pBv0nWZBiGzEUqMMUaSDYNBiiZJsPdBmryM2Q2xyQ7B+/Wq3wLfkC+tOaR2h8ndk+XKM JjVgV3kLkmpZI4NwmFAw83GIP1uo70SiRXOuxYvppmg9qjEgDoPy/5+oSGYLYA35eHZ9 KCjgCpF4SDVv3/NJAxiJ/CoTIAqByK8L+yjVWgq4+wZ86vE/Dra46KAdzBXjk2oWdbqF 3jYE+ga1ocohzJxbkmGFaxnjOvpVMPQAqrSV/xcny/yPDDEQgCHt8y1Sc3muuzEmwF01 scZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783227827; x=1783832627; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=BgEKd6Mh2oZg30kt6Uz0XcEr3ImU0ZF3LM46rmQ/KpE=; b=alSycLdroH4+XVoKKTfWfme6w/6B7MXQr9PvXrjOBps4Z+qmgspdJbaVtUoUdUTYjz Rp06dUDVRzclxPz+9299v0gNCdk2Vh6ZNbkwiUTkOYqal+1g1p0K4LtHsegI5odBcD8g auNr5JYlSpzN4bA3hwLglwI59BjMwxozy5ol626wz6iGxpkbB45aiMAU1Y2SNC/9aMZc ubXH1+E38pjlqqreBuFGEdTGO7i/uMbNI2zDpR+IUlWrLSDN6K4QXBFmtP1Cend2X2GN gZuSwGxMOUK+Oxxh8BwG4I/B+M2wVvTtXL8RvLiJ9bPzsVp8RF6c/0Yk8Spnpzk5JDYZ W/sQ== X-Forwarded-Encrypted: i=1; AHgh+RpStqAseoYsvcxcyy3rvvtnxbQIGoHXPhng0aQuTGQIz/GjkNKSEYTbLvVAhzkyoDmyYoRBD/MPzjqIZCFZ@postgresql.org X-Gm-Message-State: AOJu0YzC2dMonLNzpz5t4pSmm/loXXE4dUdTSSOAhWmjqz5HriPA5Qq8 Ptkpr399hGW56hGBEwhr4LGe8cTh4VAjk5IBJBHhh8rr3GgG0rXaP4iYpmWfUCTs9M+txssVXa2 BKTsHiwLxq+V1ox4OE/KhWDU+tAgZs2Y= X-Gm-Gg: AfdE7ck5Q4TZRf/Rx2I60i2262gpbO8qC1VCtRPiesah7Ex+EjnLirXqy8tDX+BuUos axVKb8tUt5V0vehg+2kv2YwTLd1EveC9utweis2x91d5kxUxgDmnpHxcHaZwSbG0M5INLrZ3M4f guS3VlrofT2zem4wn6DTOE73ThPE+JKBaXouXqJvFKAPWV+mmBDgB02S5kYPGEm4iO01JxrynZx d2Jo7jporG9T/r2Xv6yK8EoRzp2DGYccOBdWN6B2IobTkxNKfcrHtb9HB6lCXSVAjVkmEL9cM++ iJKX+2AkH40u+YPeuVS4jA0bGvhfYj3ZSSbrnxDlhq8CRoI7BVpysQ== X-Received: by 2002:a17:90b:4c48:b0:381:1ffc:7d35 with SMTP id 98e67ed59e1d1-3829f2f4787mr2997377a91.6.1783227826517; Sat, 04 Jul 2026 22:03:46 -0700 (PDT) MIME-Version: 1.0 References: <56821e0d-bfd5-4619-b13f-12e28c78289b@iki.fi> In-Reply-To: From: Thomas Munro Date: Sun, 5 Jul 2026 17:03:08 +1200 X-Gm-Features: AVVi8CdLJ1PS1DIOPUm_0_R5IO8sdOzkuogY7oIWxVX7znEs6I7TFLg8dd1tuRc Message-ID: Subject: Re: Can we get rid of TerminateThread() in pg_dump? To: Jelte Fennema-Nio Cc: Bryan Green , Heikki Linnakangas , pgsql-hackers , Tom Lane , Kyotaro Horiguchi Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Jul 4, 2026 at 11:15=E2=80=AFPM 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. 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 clear, I do think we should stop using TerminateThread because I > wanna replace PQcancel there with PQcancelBlocking[1] PQcancelBlocking > does a whole TLS handshake, which is almost certainly taking some locks. > > Note that the way to achieve that I moved the Ctrl+C handler to a > dedicated thread on Unix too, so it starts behaving the same as Windows > in that respect. I think combined with you changing pg_dump to use > worker *threads* on Unix too, we would then get pretty much identical > behaviour across OSes for pg_dump. I wondered about something like this too. Nice Unix/Windows convergence, and it sounds like you have no other choice if you want to do fancy non-async-signal-safe footwork.