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 1wfoPy-005hHr-29 for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Jul 2026 00:39:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wfoPv-009WFr-13 for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Jul 2026 00:39:35 +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 1wfoPv-009WFj-07 for pgsql-hackers@lists.postgresql.org; Sat, 04 Jul 2026 00:39:35 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wfoPt-00000001O73-09Ji for pgsql-hackers@postgresql.org; Sat, 04 Jul 2026 00:39:33 +0000 Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-3812af5b025so123495a91.0 for ; Fri, 03 Jul 2026 17:39:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783125572; cv=none; d=google.com; s=arc-20260327; b=Qy0dxCtruu2KeRc+908FnO870spdD/PKbawvTDu2h3If/JINjwtxrZS0n98/49EjHx toQnD5DDIi/zBguKP0PpwcfFLa/idzZXvuS66lEq0kftHj35G+AhFRzTlTrAb20GTxuX AmAQSjTCdgvTCbAT2zwbAvFoOofOVS/Fda+dg/YtFZybGv/JxitPEPn8pSD8++S3m1tj y3YyzsDxsL1Nge5gvbroxdSSOClqw6Aj/fcyDs3l3SaafWXs7oFRZH45YgG3rhXC+/Eu h1hBzmc+honLX3IONf8epdCgCfPdhvcVeikRbfqMAwY2awGpfyC4Dak3HbO4WuXRl3aC lD3A== 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=ah7B+zPE7bbHmEmii0VrbaqLy5kb5Egf65RzMJzlsis=; fh=dS3g/r4aavEskkg1090Os4JOKqHqksCtmAQKUSGioJA=; b=TbjMhQmkIaq9mQTB37pwcHw3FCYeF5QnwbFAnzoKWMkje81+KMdI3KJ+Oz6i+aJU3A gQO50Pcxk+nFW+se05liNbvKeq+hdTg2eqoMJEfXvm7jGADuJ21URk4XiKzdU4ivkRqc QXQ43Az87/i57+gGdz9U4qKfSaTrT5XKos1DZkRj4cYTsxr9Cugx76zoVHXrGCWiJPiO Hf8gC2KFjXCvzmUOczSpL1k5BM/szJma4Zt+mrJO9/GcKD7ICPXTzEfoHOdys8X+BIvN 8TK9Or5sP+1/qqLuVOomQhXxTgYmbUvCgc+dRJdQ3h65WeJn1h2rfbdW2ZzlXoM7InY0 dVRA==; 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=1783125572; x=1783730372; 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=ah7B+zPE7bbHmEmii0VrbaqLy5kb5Egf65RzMJzlsis=; b=mdKv/J38R30CoV9HEZdrXPpu4wWFDDowWsLcGkIforp7AQ5Wp/Ovz13FKw0Lvdeq73 6QX9QtMK9AZL2mv2izA3q+jDOd90SN+LBuXgWFZ0Ap9PA7XMu6vmP9aitGAIcCWY4iZD iaJD5s32/5HX7CWPtPpjpnZRqn+Tj3ygiS8CCLV0tP8doBmnVIZEoOcfcunoMp2aLV5F OuSR0xxBVmnfKeWNs0Z6/prMs7PoU8TVNYrglFarPrHCp3VljS+PS6QfjnugrpEC+c3i d/OTygXp3Gg958uF8n9LUxe+SWC318L5ESHjlFhuitoMNPe3Y7bt/UtOvTDI6Clq/jwd Iz1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783125572; x=1783730372; 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=ah7B+zPE7bbHmEmii0VrbaqLy5kb5Egf65RzMJzlsis=; b=GcqraPVv928SDvYcrcL7gRIH1A42FgRgCmGUS30I7pNeVK5E21j3ggftmRZuR0rNN0 1Px2Zoj8KnswvWFUYIaK/1VevnQ48L90WTi5adzylB4A5AhdGO/dU9SOtwST4tXpz/VJ r4UAF0Ca1qW/qInth4CcFgF4yglIKand4WIYfMinWt5xEPJTXx7Pb6oLG3FIFiA3YAd8 yr547XmgE9mUqimRMc8EZby15CiWCJb1lZLT0N6jyszphUkplbn8nXWBescWdQnV3HEA LGn7gLxQPNZ+BfkfxclreUZ84yv0XH4WBDANhFx0NMAlvUOXr+ZAP+3wNfaOTeHh0OYi MO2Q== X-Gm-Message-State: AOJu0YyYuSC3c2l62hiYE/XMvAwxyIUKHI4TEkyc04VbFKQa5y9vtX3V rBEu4A7S6UGEz3xVk7fICmFElyGxrOzWZ8rbfViNjIzhm2/HyaPGr6qYuryN7RpdH+I3k8ZyR3X R9h1I4toBC2vitomvZFluDYYnHY2jen0= X-Gm-Gg: AfdE7cn7RdSUQMGLbV29GmscN0joKRGYf5NwZ1KdIW3E3UJUvwTVwzZfUMZipHc8o1l Yk0a6Y4Vep/l0RolTzxds8/Qp9xqCg+8SEvoo/z9iIB/z6Yj38NUaLKd2iH6I/vgTDcdfE2sSPN 9cFhDUeLFlmcgWLUHPDVo+oUEAJFEthBnxdpTMHCVEwYUM3z1AaV5dgVj0sakr6qT9bplTE6peD 0GDxYikJRTsqnpf9fwdC4BpML/1mBLjVDz3/VeIWCyeHSHvxZfEhUd39/EZN49a8sYULNkKuz1x QCu5W4NYFWJpDgXaIIKNSQ4aB8yzv+WJyXA4wxoWvVhsAw7iv1aAIw== X-Received: by 2002:a17:90b:1801:b0:381:bcfb:e710 with SMTP id 98e67ed59e1d1-3829cb9af51mr901268a91.3.1783125571719; Fri, 03 Jul 2026 17:39:31 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Thomas Munro Date: Sat, 4 Jul 2026 12:38:53 +1200 X-Gm-Features: AVVi8CfwqlghmG8VlbB7348R7b5f-Ft4TQUcnLICSI14ctQoXkvh3AqClqETq7E Message-ID: Subject: Re: Can we get rid of TerminateThread() in pg_dump? To: Bryan Green Cc: 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 1:56=E2=80=AFAM Bryan Green = wrote: > It works. It compiles clean, and on a ^C during a parallel dump it > suppresses the worker cancel messages the same way the TerminateThread > call did-- I checked against unmodified master with the TerminateThread > call still in place, and the output is identical-- "terminated by user" > and nothing else. Thank you for confirming! So now I'm wondering, do we want to let sleeping dogs lie, or do we want to back-patch this? If we're happy to leave the back-branches, which have never received a user complaint, then I'll simply adopt this approach in my pg_dump-with-threads-on-Unix-too patch set (which I'll post shortly), ie the same dup2() code will be used on all systems. But if we think this problem is worth fixing in back-branches, we could back-patch this stand-alone patch first. Thoughts? > Moving write_stderr off fileno(stderr) to STDERR_FILENO is worth having > on its own: that shim's comment notes _fileno returns -1 when the stream > is closed, which is a state the shutdown path can be in. Cool. Yeah, I failed to mention why I'd done that in my previous email, and that was it. > Opening NUL in the handler worked here; I didn't need to open it in advan= ce. I was worrying that open() might fail with EMFILE. I don't think it's really going to happen though, given the bounded numbers of files that pg_dump/pg_restore should be working with, so maybe it's OK as it is. > Since you mention moving parallel.c to threads on non-Windows, I've been > replacing the socketpair/select() worker protocol on Windows with an > in-process queue (a mutex and two condition variables)[1], heading the > same direction to unify across platforms. There a worker signals its own > death through the condition variable rather than the leader seeing pipe > EOF, so ^C hits an extra pg_fatal("a worker process died unexpectedly") > in the leader-- and your redirect swallows that one too. I put your Excellent, and 100% agreed. No need for pipes/sockets and clunky protocols if the fork() path is gone. I had already made a start on exactly same idea, because I hadn't seen your thread (sorry). I have a few comments/thoughts (short version: can we make a reusable generic thread pool component for that?). I will look more closely at your patches and comment on your thread. > patch on top of that series and hit ^C on a 2.3 GB dump repeatedly at -j > 2, 4, 8, and 100: clean exit every time, "terminated by user", nothing > else. pg_stat_activity right afterward showed no live COPYs, up through > -j 100-- so the PQcancel()s land and the backends actually stop, which > TerminateThread never did. So your change composes with that work. Interesting.