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 1wffwh-005a8f-0n for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Jul 2026 15:36:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wffwg-008JSC-0O for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Jul 2026 15:36:50 +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 1wffw0-008FwQ-1l for pgsql-hackers@lists.postgresql.org; Fri, 03 Jul 2026 15:36:08 +0000 Received: from mail-yw1-x112c.google.com ([2607:f8b0:4864:20::112c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wffvy-00000001Tis-0sEl for pgsql-hackers@postgresql.org; Fri, 03 Jul 2026 15:36:08 +0000 Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-80cebd41372so8462397b3.3 for ; Fri, 03 Jul 2026 08:36:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783092964; x=1783697764; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=0i7TBgZ5wkDaiONYWosH2bsGaWjFbMvHaWJq01QcSk8=; b=RMlTQRRP3NPmzHUEizs4AhgvVQTWQCtlRNqYiVdE01DLatyHLU7G7wyFdETJ15gB+F 0geszTyyq/FCSs9/YQe08s7FnJKg401fBSTAheIbvT+mMmLj1txXb3bz5GdcjrA5YiRz dUgmbBv60ST0gS4lffUByRwfhURryOU72r4jxnL+n4itGcPmgk55mDJYWwtJQM8u/qVo BkwSt2tQdwtg3mKfDbmlx0xYbqC+uIksLc6PaZ4uFROhX0eFHjVCveexmTtgEcGNn4Ua 7Bl2s9SRdqS7pSB8AbsyHP2ym337Kpk0hDrb6ql2wwhGI2ZU9HWxSmbAo5V4WnOgKBON rTxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783092964; x=1783697764; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0i7TBgZ5wkDaiONYWosH2bsGaWjFbMvHaWJq01QcSk8=; b=a2GetjfGwE18DFPobcjfba+akm6mMUv7dQIhE8Aw9MdchRcLE+j6sQX6Mgz3RpIdJj e4l2ZZX8DeflFZJM9hG73fbD8fg1yPju65XFh0AIpgv8MZ3RmAOyq94daIkV+O1MVmVF Py+l2kYJhyPMr5oVTJKwy7l7L80lSXnC8gCIof0beu7ZBY6D8YfVgp8o8IzKyRTXuzrH /NIZwgQtALERZ/F8Th0W8B6WjDP3sGwygrdtRQiRcDYpEhaW4qa4gPy9oXcZiLR6aBgu Rk6WaspFeGA5Y++LwCpE9ZmeIBFZIZyTeQy0BCM1FMfInzxnEd5psQqvLTuA/UhOCMWd pDCg== X-Forwarded-Encrypted: i=1; AHgh+RrAxGBhNa2Pyc1x6CqTIkFJ96d3hZ2YXaj3QlkeViO5xGuIdMYeL5X4gr0zBOT4UesbvzKLrovf8yilGoXw@postgresql.org X-Gm-Message-State: AOJu0Yx4iLioSs/zOLCrab5juTAq0cY5NRd6h5kLDHTUBISlInQzSjkl xp8flvHXpFmc1w1+kwxnm2mVkF9kNGJuquJJIvDFUehxqW3kSn8ofZ3+ X-Gm-Gg: AfdE7ckGUYYaWrv6qRTryfuptukGVgIOIAIhyiDhQNolJbZM6Hb7t5rrT5eArqi/6PQ 8wHTnC7oxnkbtzNxjaZHD6ECXUrtAQXJTwSZgOS7dvE6HhFiI7GGXJrOu62ImTkhW1Bw544o0WZ 6ws2xjjEvIukao4Csy1fFO0iFBXgkzuCrVrptGW5ziLWDv2A2U9avkcubRWbN8R1ot/iHomQfEW 9RB2FkKht+5h3ijKVKQfK7KS4RGDUxAO24btTxfmaCEN72zCbkxkBYfOZDMhvlx8o8VxKv6xJMQ rn4lSKfRm7kjNSaZMfi8qA6os/fG3faj3v5ifGBJtzgTR2wWPRphg5jbNUQcr8Q0t4reP84NeiV bEChaDcJgHhYebPSlQ2pCvGSJh6rE5BIgNvCXRNCexmGRoHM8BJXjOxKcay5+BcE2d74VHN+dtH IM/AiPlmwhBr+DICRhAABE7TVt8XhpGvx+dyu8g+faLz2bYZFQ37nU2tUnIy51BwsaXl6GdGbcC JxppbU74vdC9M2n4aAanelVHw== X-Received: by 2002:a05:690c:6908:b0:80d:964f:88fd with SMTP id 00721157ae682-8171dce3662mr2672067b3.5.1783092963878; Fri, 03 Jul 2026 08:36:03 -0700 (PDT) Received: from ?IPV6:2600:1700:8952:80:c066:d6c3:fa90:ffd1? ([2600:1700:8952:80:c066:d6c3:fa90:ffd1]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-666405289f2sm933101d50.7.2026.07.03.08.36.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Jul 2026 08:36:03 -0700 (PDT) Message-ID: Date: Fri, 3 Jul 2026 10:35:35 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Can we get rid of TerminateThread() in pg_dump? To: Heikki Linnakangas , Thomas Munro , pgsql-hackers Cc: Tom Lane , Kyotaro Horiguchi References: <56821e0d-bfd5-4619-b13f-12e28c78289b@iki.fi> Content-Language: en-US From: Bryan Green In-Reply-To: <56821e0d-bfd5-4619-b13f-12e28c78289b@iki.fi> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/3/2026 10:05 AM, Heikki Linnakangas wrote: > On 03/07/2026 06:32, Thomas Munro wrote: >> Following up on this ancient discussion and resulting commit e652273e... >> >> https://www.postgresql.org/message-id/ >> flat/11515.1464961470%40sss.pgh.pa.us#3e78a2af445dd7e566cf499023e8cb97 >> >> write(fd, ...) locks fd's entry in a user space descriptor table on >> Windows, so if the terminated thread was also writing to stderr, I am >> pretty sure it would hang.  Someone with Windows might be able to >> repro that by hacking the workers to write to stderr a lot? >> WriteFile(_get_osfhandle(STDERR_FILENO), ...) might avoid that >> specific issue, but for all I know that's just the tip of the iceberg >> considering the socket stuff. >> >> 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 worker > threads, you can refrain from printing the cancellation error if the > flag is set. > > Dunno how complicated that is to change.. > > - Heikki > > > 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). -- Bryan Green EDB: https://www.enterprisedb.com