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 1wapgZ-0025kn-1K for pgsql-hackers@arkaria.postgresql.org; Sat, 20 Jun 2026 07:00:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wapgW-000mkT-1F for pgsql-hackers@arkaria.postgresql.org; Sat, 20 Jun 2026 07:00:08 +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 1wapgV-000mkL-2i for pgsql-hackers@lists.postgresql.org; Sat, 20 Jun 2026 07:00:08 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wapgT-00000001FmF-47on for pgsql-hackers@postgresql.org; Sat, 20 Jun 2026 07:00:06 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4923139e940so16357065e9.3 for ; Sat, 20 Jun 2026 00:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781938803; x=1782543603; darn=postgresql.org; h=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=ywgsPvWVneb/RBflBs+sEXWAoCsny+BzWV0Q0rnv/0w=; b=an7iWgvQhHTolOn7Xpw+A9p+skZogyjMkbz6tgJe8QdcS++yrFyrt+LJfGYOyuFz2E 6GW0YxAcnb4eNNpYLt+SiBOWb8oUh6RJXe6zXnJQ760rkqe6jODIX8T7UK3g9oacnur5 tTBvQM1LSPMeIQ4fs8QGeju3J//AXmwBt7hBu0Am9gvBuCjl6wk6bysF3NO7LUDcdvct R9Yffrmr60MGRAnAabpqeUFcPxzP3einxS09JNG/JL673oAWttxn/skmVgrzO3lK8iZA Pwsfx6Bsc3sWC+DtCsJxnFaC9rYSLya/ltnH4viouxOrTJBV1rzGYKP9KlFvcwT4XAm1 /o9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781938803; x=1782543603; h=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=ywgsPvWVneb/RBflBs+sEXWAoCsny+BzWV0Q0rnv/0w=; b=WbgkFJ2g2gV9jymKbDoqA4KficuGGL4ufYV6SdFMZxeqqfuKuxfQ5o3ZAXZ0JNGYcP qFcUraOD90u1pxTOpzI2X7ZZSLAH/W5NcF1hYwlqFItEcZtvTHbBADzeteHQdXNvGNta wRici+rmQPyVDFxgEQ6BD7pFywB1YuAJGrxIgFxZKipwU7gUsJ/Z6yMiy41borF0FEG3 Y/ny6nWPHmyVWzCPdjXZj3SSiok/McfLfwMO6zGPZyjxZcYkE6tOFSDRkiCJKcE61nNE lROhtwKqqVKybF3g4/4r6bbwc4XaAP+2u0u20gWQ46aTdSmYeSienJ6BsDD+A++pfX14 XAYg== X-Forwarded-Encrypted: i=1; AFNElJ8f6skL6Rjqs6DA/P6W2/FIK8nQV5D6p/0RIwoO2oBYuWSmFGIuXkyBxhF5aMj/68d1FS38/ZNlcEAJ4Dg+@postgresql.org X-Gm-Message-State: AOJu0Yy1WP14nLuLqI63HmtYQJXK4g9JB3rXsQOHCFaEgs0uOlSAUz94 gImVSM8sdp4xPV4+tCVBB4SpXnAqInboU+Vi3NGeKhJPvH2ZcxFxA8ET X-Gm-Gg: AfdE7ckzUh0KwMLQDqbGX0Fh/lmSTAjH9d/mJiz8lpGrxbqfl3DO6PWjjX4/NXmaslK IXTxq9ssrGoX1XDUJ5MKYYZJyM9Oe9jauZZra9dod5WWBROegbrNESyfkitbfCUT9EEBByxn5Pj KehdXfgpbICgCymGUTXcZfCq7t3HWuD+dGlNydoT+MznEV67u7oWIm3maAxcio1aeagrTn5ppbl 8XDHEgO3BnWUortxDHvbzPgfkalJIIP+iNXvA0zokqv4eG2mJgquv8arYN6kT4V0Jv3JeHcX5bj L+8zWu+obwOd1MgbAz6YDpg/viqOdyVFi3b7kxmzN0ErOafH9LlKpmQUigshkPRojhvJIo9bsMh GOgBKwjSlxDBZFxCheG6nYVR+ZQCXywL33nXcHEsZ3hsq23+HuCSfeJFjfwN8CZBd+qTDiLZTbs ZsTigzxMhJZfote4Q= X-Received: by 2002:a05:600c:b8d:b0:490:9588:bdb6 with SMTP id 5b1f17b1804b1-4924258f73amr78257855e9.33.1781938802952; Sat, 20 Jun 2026 00:00:02 -0700 (PDT) Received: from [192.168.0.50] ([89.149.120.180]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4923fd21dbdsm114041115e9.6.2026.06.20.00.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 20 Jun 2026 00:00:02 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------OYdBfeIvqjJKRZpCp20WOCMy" Message-ID: Date: Sat, 20 Jun 2026 10:00:01 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] O_CLOEXEC not honored on Windows - handle inheritance chain To: Bryan Green Cc: Tom Lane , Thomas Munro , pgsql-hackers References: <7f6779d5-7a0e-44c5-a85f-b4ef265db766@gmail.com> <35f9236e-95d8-4f31-ac6b-ec54b7de4bac@gmail.com> <7412f694-7c57-41e5-ae37-71136070b0da@gmail.com> <1086088.1765593851@sss.pgh.pa.us> Content-Language: en-US From: Alexander Lakhin In-Reply-To: <1086088.1765593851@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------OYdBfeIvqjJKRZpCp20WOCMy Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hello Bryan, 13.12.2025 04:44, Tom Lane wrote: > Thomas Munro writes: >> Hearing nothing, pushed. > fairywren is unimpressed: Now that fairywren is pretty satisfied with the test, it has produced an interesting failure [1]: 208/222 postgresql:test_cloexec / test_cloexec/001_cloexec                        ERROR 4.09s   exit status 1 regress_log_001_cloexec [14:36:36.820](1.047s) 1..1 [14:36:36.821](0.001s) # Using test program: C:\\tools\\xmsys64\\home\\pgrunner\\bf\\root\\REL_16_STABLE\\pgsql.build\\tmp_install\\tools\\xmsys64\\home\\pgrunner\\bf\\root\\REL_16_STABLE\\inst\\bin\\test_cloexec.exe [14:36:37.445](0.624s) # Test program output: [14:36:37.446](0.001s) # Child: Received HANDLE1=00000000000000B0 (should fail - O_CLOEXEC) # Child: Received HANDLE2=00000000000000C0 (should work - no O_CLOEXEC) # Child: Successfully wrote to HANDLE1 # Child: Successfully wrote to HANDLE2 # Child: HANDLE1 (O_CLOEXEC): ACCESSIBLE (BAD!) # Child: HANDLE2 (no O_CLOEXEC): ACCESSIBLE (GOOD!) # Child: Test FAILED - O_CLOEXEC not working correctly # Parent: Opening test files... # Parent: fd1=3 (O_CLOEXEC) -> HANDLE=00000000000000B0 # Parent: fd2=4 (no O_CLOEXEC) -> HANDLE=00000000000000C0 # Parent: Spawning child process... # Parent: Command line: "C:\\tools\\xmsys64\\home\\pgrunner\\bf\\root\\REL_16_STABLE\\pgsql.build\\tmp_install\\tools\\xmsys64\\home\\pgrunner\\bf\\root\\REL_16_STABLE\\inst\\bin\\test_cloexec.exe" 00000000000000B0 00000000000000C0 # Parent: Waiting for child process... # Parent: Child exit code: 1 # Parent: FAILURE - O_CLOEXEC not working correctly [14:36:37.447](0.002s) not ok 1 - O_CLOEXEC prevents handle inheritance [14:36:37.448](0.001s) #   Failed test 'O_CLOEXEC prevents handle inheritance' #   at C:/tools/xmsys64/home/pgrunner/bf/root/REL_16_STABLE/pgsql/src/test/modules/test_cloexec/t/001_cloexec.pl line 57. [14:36:37.449](0.001s) # Looks like you failed 1 test of 1. I've managed to reproduce it locally with: --- a/src/test/modules/test_cloexec/t/001_cloexec.pl +++ b/src/test/modules/test_cloexec/t/001_cloexec.pl @@ -19,3 +19,3 @@ if (!$PostgreSQL::Test::Utils::windows_os) -plan tests => 1; +plan tests => 1000; @@ -44,2 +44,4 @@ note("Using test program: $test_prog"); +for (my $i = 1; $i <= 1000; $i++) +{  my ($stdout, $stderr); @@ -58,3 +60,3 @@ ok($result && $stdout =~ /SUCCESS.*O_CLOEXEC behavior verified/s,     "O_CLOEXEC prevents handle inheritance"); - +}  done_testing(); and with the test cloned: perl -i.bak -ne "print unless /test_cloexec_/" "src/test/modules/meson.build" && python3 -c "for i in range(1,50+1):import os;import shutil;sd=\"src/test/modules/test_cloexec/\";td=f\"src/test/modules/test_cloexec_{i}\";shutil.rmtree(td,ignore_errors=1);shutil.copytree(sd, td);assert(os.system(f'perl -i.bak -pe \"s#(subdir.\'test_cloexec\'.)#subdir(\'test_cloexec_{i}\'){chr(92)}n{chr(92)}1#\" \"src/test/modules/meson.build\"')==0);assert(os.system(f'perl -i.bak -pe \"s#: \'test_cloexec\',#: \'test_cloexec_{i}\',#\" \"{td}/meson.build\"')==0)" meson test test_cloexec_*/001_cloexec --num-processes 50 failed for me as below: Ok:                19 Fail:              31 # grep 'not ok' meson-logs/testlog.txt not ok 541 - O_CLOEXEC prevents handle inheritance not ok 303 - O_CLOEXEC prevents handle inheritance not ok 798 - O_CLOEXEC prevents handle inheritance not ok 901 - O_CLOEXEC prevents handle inheritance not ok 634 - O_CLOEXEC prevents handle inheritance not ok 640 - O_CLOEXEC prevents handle inheritance not ok 770 - O_CLOEXEC prevents handle inheritance not ok 938 - O_CLOEXEC prevents handle inheritance not ok 420 - O_CLOEXEC prevents handle inheritance not ok 674 - O_CLOEXEC prevents handle inheritance not ok 114 - O_CLOEXEC prevents handle inheritance not ok 649 - O_CLOEXEC prevents handle inheritance not ok 51 - O_CLOEXEC prevents handle inheritance not ok 692 - O_CLOEXEC prevents handle inheritance not ok 874 - O_CLOEXEC prevents handle inheritance not ok 955 - O_CLOEXEC prevents handle inheritance not ok 690 - O_CLOEXEC prevents handle inheritance not ok 33 - O_CLOEXEC prevents handle inheritance not ok 116 - O_CLOEXEC prevents handle inheritance not ok 398 - O_CLOEXEC prevents handle inheritance not ok 773 - O_CLOEXEC prevents handle inheritance not ok 2 - O_CLOEXEC prevents handle inheritance not ok 253 - O_CLOEXEC prevents handle inheritance not ok 10 - O_CLOEXEC prevents handle inheritance not ok 902 - O_CLOEXEC prevents handle inheritance not ok 848 - O_CLOEXEC prevents handle inheritance not ok 832 - O_CLOEXEC prevents handle inheritance not ok 38 - O_CLOEXEC prevents handle inheritance not ok 986 - O_CLOEXEC prevents handle inheritance not ok 688 - O_CLOEXEC prevents handle inheritance not ok 872 - O_CLOEXEC prevents handle inheritance not ok 582 - O_CLOEXEC prevents handle inheritance not ok 816 - O_CLOEXEC prevents handle inheritance not ok 277 - O_CLOEXEC prevents handle inheritance not ok 570 - O_CLOEXEC prevents handle inheritance not ok 691 - O_CLOEXEC prevents handle inheritance not ok 871 - O_CLOEXEC prevents handle inheritance not ok 770 - O_CLOEXEC prevents handle inheritance not ok 108 - O_CLOEXEC prevents handle inheritance not ok 610 - O_CLOEXEC prevents handle inheritance not ok 866 - O_CLOEXEC prevents handle inheritance not ok 909 - O_CLOEXEC prevents handle inheritance not ok 276 - O_CLOEXEC prevents handle inheritance not ok 190 - O_CLOEXEC prevents handle inheritance It looks like HANDLE1 passed from parent to child can accidentally point to a child slot occupied by some other writable object, not inherited from parent. [1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=fairywren&dt=2026-06-19%2013%3A28%3A44 Best regards, Alexander --------------OYdBfeIvqjJKRZpCp20WOCMy Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Hello Bryan,

13.12.2025 04:44, Tom Lane wrote:
Thomas Munro <thomas.munro@gmail.com> writes:
Hearing nothing, pushed.
fairywren is unimpressed:

Now that fairywren is pretty satisfied with the test, it has produced an
interesting failure [1]:
208/222 postgresql:test_cloexec / test_cloexec/001_cloexec                        ERROR             4.09s   exit status 1

regress_log_001_cloexec
[14:36:36.820](1.047s) 1..1
[14:36:36.821](0.001s) # Using test program: C:\\tools\\xmsys64\\home\\pgrunner\\bf\\root\\REL_16_STABLE\\pgsql.build\\tmp_install\\tools\\xmsys64\\home\\pgrunner\\bf\\root\\REL_16_STABLE\\inst\\bin\\test_cloexec.exe
[14:36:37.445](0.624s) # Test program output:
[14:36:37.446](0.001s) # Child: Received HANDLE1=00000000000000B0 (should fail - O_CLOEXEC)
# Child: Received HANDLE2=00000000000000C0 (should work - no O_CLOEXEC)
# Child: Successfully wrote to HANDLE1
# Child: Successfully wrote to HANDLE2
# Child: HANDLE1 (O_CLOEXEC): ACCESSIBLE (BAD!)
# Child: HANDLE2 (no O_CLOEXEC): ACCESSIBLE (GOOD!)
# Child: Test FAILED - O_CLOEXEC not working correctly
# Parent: Opening test files...
# Parent: fd1=3 (O_CLOEXEC) -> HANDLE=00000000000000B0
# Parent: fd2=4 (no O_CLOEXEC) -> HANDLE=00000000000000C0
# Parent: Spawning child process...
# Parent: Command line: "C:\\tools\\xmsys64\\home\\pgrunner\\bf\\root\\REL_16_STABLE\\pgsql.build\\tmp_install\\tools\\xmsys64\\home\\pgrunner\\bf\\root\\REL_16_STABLE\\inst\\bin\\test_cloexec.exe" 00000000000000B0 00000000000000C0
# Parent: Waiting for child process...
# Parent: Child exit code: 1
# Parent: FAILURE - O_CLOEXEC not working correctly
[14:36:37.447](0.002s) not ok 1 - O_CLOEXEC prevents handle inheritance
[14:36:37.448](0.001s) #   Failed test 'O_CLOEXEC prevents handle inheritance'
#   at C:/tools/xmsys64/home/pgrunner/bf/root/REL_16_STABLE/pgsql/src/test/modules/test_cloexec/t/001_cloexec.pl line 57.
[14:36:37.449](0.001s) # Looks like you failed 1 test of 1.

I've managed to reproduce it locally with:
--- a/src/test/modules/test_cloexec/t/001_cloexec.pl
+++ b/src/test/modules/test_cloexec/t/001_cloexec.pl
@@ -19,3 +19,3 @@ if (!$PostgreSQL::Test::Utils::windows_os)

-plan tests => 1;
+plan tests => 1000;

@@ -44,2 +44,4 @@ note("Using test program: $test_prog");

+for (my $i = 1; $i <= 1000; $i++)
+{
 my ($stdout, $stderr);
@@ -58,3 +60,3 @@ ok($result && $stdout =~ /SUCCESS.*O_CLOEXEC behavior verified/s,
    "O_CLOEXEC prevents handle inheritance");
-
+}
 done_testing();

and with the test cloned:
perl -i.bak -ne "print unless /test_cloexec_/" "src/test/modules/meson.build" && python3 -c "for i in range(1,50+1):import os;import shutil;sd=\"src/test/modules/test_cloexec/\";td=f\"src/test/modules/test_cloexec_{i}\";shutil.rmtree(td,ignore_errors=1);shutil.copytree(sd, td);assert(os.system(f'perl -i.bak -pe \"s#(subdir.\'test_cloexec\'.)#subdir(\'test_cloexec_{i}\'){chr(92)}n{chr(92)}1#\" \"src/test/modules/meson.build\"')==0);assert(os.system(f'perl -i.bak -pe \"s#: \'test_cloexec\',#: \'test_cloexec_{i}\',#\" \"{td}/meson.build\"')==0)"

meson test test_cloexec_*/001_cloexec --num-processes 50
failed for me as below:
Ok:                19
Fail:              31

# grep 'not ok' meson-logs/testlog.txt
not ok 541 - O_CLOEXEC prevents handle inheritance
not ok 303 - O_CLOEXEC prevents handle inheritance
not ok 798 - O_CLOEXEC prevents handle inheritance
not ok 901 - O_CLOEXEC prevents handle inheritance
not ok 634 - O_CLOEXEC prevents handle inheritance
not ok 640 - O_CLOEXEC prevents handle inheritance
not ok 770 - O_CLOEXEC prevents handle inheritance
not ok 938 - O_CLOEXEC prevents handle inheritance
not ok 420 - O_CLOEXEC prevents handle inheritance
not ok 674 - O_CLOEXEC prevents handle inheritance
not ok 114 - O_CLOEXEC prevents handle inheritance
not ok 649 - O_CLOEXEC prevents handle inheritance
not ok 51 - O_CLOEXEC prevents handle inheritance
not ok 692 - O_CLOEXEC prevents handle inheritance
not ok 874 - O_CLOEXEC prevents handle inheritance
not ok 955 - O_CLOEXEC prevents handle inheritance
not ok 690 - O_CLOEXEC prevents handle inheritance
not ok 33 - O_CLOEXEC prevents handle inheritance
not ok 116 - O_CLOEXEC prevents handle inheritance
not ok 398 - O_CLOEXEC prevents handle inheritance
not ok 773 - O_CLOEXEC prevents handle inheritance
not ok 2 - O_CLOEXEC prevents handle inheritance
not ok 253 - O_CLOEXEC prevents handle inheritance
not ok 10 - O_CLOEXEC prevents handle inheritance
not ok 902 - O_CLOEXEC prevents handle inheritance
not ok 848 - O_CLOEXEC prevents handle inheritance
not ok 832 - O_CLOEXEC prevents handle inheritance
not ok 38 - O_CLOEXEC prevents handle inheritance
not ok 986 - O_CLOEXEC prevents handle inheritance
not ok 688 - O_CLOEXEC prevents handle inheritance
not ok 872 - O_CLOEXEC prevents handle inheritance
not ok 582 - O_CLOEXEC prevents handle inheritance
not ok 816 - O_CLOEXEC prevents handle inheritance
not ok 277 - O_CLOEXEC prevents handle inheritance
not ok 570 - O_CLOEXEC prevents handle inheritance
not ok 691 - O_CLOEXEC prevents handle inheritance
not ok 871 - O_CLOEXEC prevents handle inheritance
not ok 770 - O_CLOEXEC prevents handle inheritance
not ok 108 - O_CLOEXEC prevents handle inheritance
not ok 610 - O_CLOEXEC prevents handle inheritance
not ok 866 - O_CLOEXEC prevents handle inheritance
not ok 909 - O_CLOEXEC prevents handle inheritance
not ok 276 - O_CLOEXEC prevents handle inheritance
not ok 190 - O_CLOEXEC prevents handle inheritance

It looks like HANDLE1 passed from parent to child can accidentally point
to a child slot occupied by some other writable object, not inherited from
parent.

[1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=fairywren&dt=2026-06-19%2013%3A28%3A44

Best regards,
Alexander
--------------OYdBfeIvqjJKRZpCp20WOCMy--