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 1wfobo-005hRu-1b for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Jul 2026 00:51:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wfobn-009YMe-0e for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Jul 2026 00:51:51 +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 1wfobm-009YMV-2y for pgsql-hackers@lists.postgresql.org; Sat, 04 Jul 2026 00:51:50 +0000 Received: from mail-vs1-xe2a.google.com ([2607:f8b0:4864:20::e2a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wfobk-00000001YtG-3rfA for pgsql-hackers@postgresql.org; Sat, 04 Jul 2026 00:51:50 +0000 Received: by mail-vs1-xe2a.google.com with SMTP id ada2fe7eead31-737d7440b6eso30222137.3 for ; Fri, 03 Jul 2026 17:51:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783126307; cv=none; d=google.com; s=arc-20260327; b=MUhbesMVx+pb9TDGeTbX1qoiQa3uAZjGdmfy6lQgc0DPDzuL8nDaiinCsqkzAMu+Ky Mdw6b1H4H5B7qUGdIjzqsUPMpCBCWrIODKGP08qZs30aVtVvoavL7Yq7ai8O4FDR+W8E 7f+bZfvDEvd1DnUV0Y34mESNioS8jBv54GrnN1b1Vc+/RglZoJkTbrhq2dZaZAda+LME dEEFYuczksNGb5RP7E/Wev3TODnsWp38aIiMnJd/dkzMrhd2N9zOPapIkEA0JWBKlTO6 TsJRgeLonh0IN+OY08or6kqgtx8/mORPNTADfSzeV/MWjLosCuHAhfAh9agWXJpqnvbK 99JQ== 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=3bcXNzVATncdQu3jLoa5UINfH8LSyMZqmjRHIo3IxCM=; fh=yf+HQa/9iVNCa6at8SwLjLZPTcjbxPGR6YOn4oH7+WQ=; b=c02fyY7w4FoY4LQXjP0/Q1vqzu07Kx9Uye3qlAiMsrkn672Dx56gDCk5r/IOmYLcTi tYtNLSucYj5ZhLPLwsssXcezW1ceXtWcRODtLUzX6kHiBrfhjqvhJJXrYMiao8rDwfa/ laKYK3jeW7DmAEH239Co5QiOATjsfOpdP0fadPnZE/NSN4Nj1szCg9sQJcHFaA2Pq0vQ /DfdLy2nDpXfQTpFCVoiN/mTt3HTDaZeUolBlO3dpGblkCPsAj8RtasPZyi8joBU7G5X aiHr7VX2rBFAgRadnjOa/dPTP73xgMx8aPzqqKNRveGl/HGVMZNbFa+lWXIkPeWyBp+N CmcQ==; 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=1783126307; x=1783731107; 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=3bcXNzVATncdQu3jLoa5UINfH8LSyMZqmjRHIo3IxCM=; b=JBAuwrEtlAxHFZz8oVHGB61mjoRCYAcHudTahvpSi7wwG0F/pPCHYMMBDS15lpWM1/ 6bQAjKCLo4gycNvYE7luzB+io7PuGxIxxRkXPLHxGjN4VoryPjsobd5qG/TuLQCYYjzn swNsonES1hNYJVoDbLmsQl8ChxSiHXS3pT0oY62vimPfbQ6oMj0inQT/EnoRulYC0vKR swu8Fez5SixmHgWu8puH4JqWmi4sC0BkMDP5pbCHdBqKy/Q9CFiXkZPg8yuWTh5NPHxD sndDg1WJaZ9VNhsurNZ1S00RT9YBj5o/y/ZAYzEbfsIuECZ2KXXMXIfgAw3txXinCRyf NAag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783126307; x=1783731107; 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=3bcXNzVATncdQu3jLoa5UINfH8LSyMZqmjRHIo3IxCM=; b=DRaV6ZAf3A1s+At3wfH6UG7JiHqjyFnvXE5dP7VWEC52f3ZBgVGnlU0u1M8RWpc418 1h9PLAqCuzjwkA5PlHFGBKcJag9V0daQY2AW62F1dpBRhoOP3C0xf/2A7Uu/WeqW2C3c xyXMlubDRDKytNlMyhD5EdHmq0HKrnSYdy0vCBl3CTKZnRT57L5Vdl9YH9phl0ggLFGh /enielotl0S7p3Ix5a+kDW0NtgA6/qv2CX56Pheze84D4icTJegUTHA3oy8b3qyqSkeO nDVSOa+/YQ4s48CwghYMSq4boR7GG/GjKz/75X3axwdcy8wlyiVS529WbBU7gLtu/u48 /O3g== X-Forwarded-Encrypted: i=1; AHgh+Rr26RI2Jo0WboO7pn4ogN4BozWshQyIPmqHGNH3i/3MPIr1wNl1wvyGKc/FrUDCs+uzwV+VnXiR8dHUcklJ@postgresql.org X-Gm-Message-State: AOJu0Yx1By85nb5aLmxlir++4zi6HBVT7dWoZZgxVu4VTO3nyB1tapBv TeWZoJC+txtK4iq99caJU/r/iRjtCLB0UGPyIzY3xU35n9zWSXy5vlwYf6+TjHOAyY/W0POAIKW jXANwatMJcfe+8xaI2RrkeiMsN3IX3Czoiw== X-Gm-Gg: AfdE7cmQsPchSomCFB1kLYc8jU623HL7FV9eN9WDgFL4iIRE17gVoQd3f42EBcA7kWT atkAXzsHcez8bCTMFGB2XDqOIqRhpFggx+1N6+Je20oKwBHd3bqdLLfUj3n77CnhWxBymDFpG5y 8oVgnG4vOEDq9+q3A+QBWY89NzQNJvLvrlkEm10synTeCLRRm0g3xCUyKfHbDK2ZpwQcNcyNUU/ xtomTlW0hujFO96GyElCrjyC8KvJhSPb7Tq7Gc8iBPDpVaqqzjXQr9WlYASEf8Z6498osOyPRWC JGadOhr7jLE5VU85OJ9VkASfY7VAg/Oq8ZhXO8pM6o9iyxKcFYDjmQ== X-Received: by 2002:a05:6102:5815:b0:738:befa:e851 with SMTP id ada2fe7eead31-74207ae0403mr268450137.8.1783126306754; Fri, 03 Jul 2026 17:51:46 -0700 (PDT) MIME-Version: 1.0 References: <56821e0d-bfd5-4619-b13f-12e28c78289b@iki.fi> In-Reply-To: From: Thomas Munro Date: Sat, 4 Jul 2026 12:51:08 +1200 X-Gm-Features: AVVi8CcrC0HLeX0odobx_vGpx7lrn9MDy-CujJJDRGcqUt_JvTo6Ew1SZHCHhz8 Message-ID: Subject: Re: Can we get rid of TerminateThread() in pg_dump? To: Bryan Green Cc: 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 3:36=E2=80=AFAM Bryan Green = wrote: > On 7/3/2026 10:05 AM, Heikki Linnakangas wrote: > >> Apparently this hasn't been a problem in practice. Error reporting > >> coinciding with ^C must be unlikely? I'd still like to find a > >> non-evil way to suppress log output, though. What if we atomically > >> pointed STDERR_FILENO to /dev/null, with dup2()? I wrote a patch to > >> try that idea out, but I don't have Windows, so I'm sharing this as a > >> curiosity in case anyone wants to try it and/or comment on all this. > >> Or has a better idea. Preferably that would work on Windows and Unix > >> (if it also used threads). > > > > Huh, that's pretty hacky. I think we should adopt our usual signal > > handling approach here: Instead of calling PQcancel() from the signal > > handler (or consoleHandler()), just set a global flag, wake up the main > > thread, and perform the cancellation from the main thread. In the worke= r > > threads, you can refrain from printing the cancellation error if the > > flag is set. > > > > Dunno how complicated that is to change.. > The main thread is waiting at the select()...waking that from a > different thread is going to be doable but awkward in the current > implementation on Windows (pipe and sockets). I agree that, in general, cooperative/flag based interruption is the right architecture and standard approach, and I did think a bit about how to make that work, but I couldn't figure out how to do it without introducing extra waits. You'd have to ask each thread to shut down and wait for it to acknowledge your request, but this is supposed to be a fast shutdown, and abnormal termination. We're subseconds away from _exit() nuking everything, and we really just want to tell the *server* to cancel whatever it's doing so we don't leave a long CREATE INDEX or whatever running. 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. With this approach we don't have to, we just disconnect them from stderr slightly before the kernel vaporises them. Doesn't seem that bad to me?