Skip to content

sws: fix binding to unix socket on Windows#19812

Closed
vszakats wants to merge 12 commits intocurl:masterfrom
vszakats:wunixsocks
Closed

sws: fix binding to unix socket on Windows#19812
vszakats wants to merge 12 commits intocurl:masterfrom
vszakats:wunixsocks

Conversation

@vszakats
Copy link
Member

@vszakats vszakats commented Dec 2, 2025

Windows 10.17063+ (having unix socket support) fails to set for unix
sockets the SO_REUSEADDR option, with error 10045 (WSAEOPNOTSUPP),
and also fails to set SO_KEEPALIVE with error 10042 (WSAENOPROTOOPT).

Fix by not enabling these socket options on Windows for unix sockets.

Also:

Ref: https://stackoverflow.com/questions/68791319/unix-domain-socket-bind-failed-in-windows/68794755#68794755
Ref: #19810


https://github.com/curl/curl/pull/19812/files?w=1

@vszakats vszakats added the Windows Windows-specific label Dec 2, 2025
@github-actions github-actions bot added the tests label Dec 2, 2025
@vszakats vszakats changed the title sws: fix binding to unix socket on Windows sws: fix binding to Unix socket on Windows Dec 2, 2025
@vszakats
Copy link
Member Author

vszakats commented Dec 2, 2025

Next:

=== Start of file http_unix_server.log
 16:52:47.609949 Running HTTP unix version on C:/msys64/tmp/curl-http-hfGQXSvC
 16:52:47.611328 Wrote pid 4202056 to log/6/server/http_unix_server.pid
 16:52:47.611550 Wrote port 8999 to log/6/server/http_unix_server.port
 16:52:49.437513 setsockopt(SO_KEEPALIVE) failed with error (10042) Protocol option is unsupported
 16:52:49.437670 accept_connection 388 returned -1
 16:52:49.438145 unlink(C:/msys64/tmp/curl-http-hfGQXSvC) = 0 (The operation completed successfully.)
 16:52:49.440305 ========> sws quits

@vszakats
Copy link
Member Author

vszakats commented Dec 2, 2025

Could these sockopt tweaks be applied to non-Windows, too?

@dfandrich
Copy link
Contributor

Is this the solution to #11258?

@vszakats
Copy link
Member Author

vszakats commented Dec 2, 2025

This fixes 10045 (WSAEOPNOTSUPP) and 10042 (WSAENOPROTOOPT).
In #11258 the error was different: 10047 (WSAEAFNOSUPPORT) which may
be caused by support missing from the OS? Unix socket requires Windows 10
17063, or a matching revision of Server 2019 (I guess [1]. The versioning is
opaque to me.)

sc query afunix is the command to query the OS about this.

Current GHA jobs run on Windows Server 2022, which should all support it.

If we had a link to one of the old failing AppVeyor jobs, we may be able to see
more clues. It seems the MSYS2 uname shows the Windows revision, and it's
shown by runtests.

@vszakats
Copy link
Member Author

vszakats commented Dec 3, 2025

Before:
TESTDONE: 1665 tests out of 1675 reported OK: 99%
https://github.com/curl/curl/actions/runs/19865130660/job/56925629275

After:
TESTDONE: 1666 tests out of 1677 reported OK: 99%
https://github.com/curl/curl/actions/runs/19867033883/job/56968244177?pr=19812

@vszakats
Copy link
Member Author

vszakats commented Dec 3, 2025

Ref dfa84a0

@vszakats
Copy link
Member Author

vszakats commented Dec 3, 2025

Fixing socksd test server enabled 3 more tests. All fail due a 3rd issue:

FAIL 1467: 'HTTP GET via SOCKS5 proxy via Unix sockets' HTTP, HTTP GET, SOCKS5, UnixSockets
FAIL 1468: 'HTTP GET with hostname using SOCKS5h via Unix sockets' HTTP, HTTP GET, SOCKS5, SOCKS5h, UnixSockets
FAIL 1470: 'HTTPS GET with hostname using SOCKS5h via Unix sockets' HTTPS, HTTP, HTTP GET, SOCKS5, SOCKS5h, UnixSockets

Opened #19825

@vszakats vszakats marked this pull request as draft December 4, 2025 00:24
@vszakats vszakats force-pushed the wunixsocks branch 3 times, most recently from 64dd49b to 1f65527 Compare December 4, 2025 17:35
```
=== Start of file http_unix_server.log
 16:52:47.609949 Running HTTP unix version on C:/msys64/tmp/curl-http-hfGQXSvC
 16:52:47.611328 Wrote pid 4202056 to log/6/server/http_unix_server.pid
 16:52:47.611550 Wrote port 8999 to log/6/server/http_unix_server.port
 16:52:49.437513 setsockopt(SO_KEEPALIVE) failed with error (10042) Protocol option is unsupported
 16:52:49.437670 accept_connection 388 returned -1
 16:52:49.438145 unlink(C:/msys64/tmp/curl-http-hfGQXSvC) = 0 (The operation completed successfully.)
 16:52:49.440305 ========> sws quits
```
https://github.com/curl/curl/actions/runs/19866365047/job/56930177145?pr=19812
https://github.com/curl/curl/pull/19810/files

sock5 sockets fail
```
test 1467...[HTTP GET via SOCKS5 proxy via Unix sockets]

 1467: protocol FAILED!
 There was no content at all in the file log/1/server.input.
 Server glitch? Total curl failure? Returned: 7
== Contents of files in the log/1/ directory after test 1467
=== Start of file commands.log
 ../src/curl.exe -q --output log/1/curl1467.out  --include --trace-ascii log/1/trace1467 --trace-time --socks5 localhost/tmp/curl-socksd-xe3LMbVY http://127.0.0.1:64407/1467 > log/1/stdout1467 2> log/1/stderr1467
=== End of file commands.log
=== Start of file http_server.log
 14:11:54.529549 ====> Client connect
 14:11:54.529749 accept_connection 276 returned 528
 14:11:54.529874 accept_connection 276 returned 0
 14:11:54.530257 Read 97 bytes
 14:11:54.530339 Process 97 bytes request
 14:11:54.530599 Got request: GET /verifiedserver HTTP/1.1
 14:11:54.530813 Are-we-friendly question received
 14:11:54.531012 Wrote request (97 bytes) input to log/1/server.input
 14:11:54.531204 Identifying ourselves as friends
 14:11:54.531531 Response sent (58 bytes) and written to log/1/server.response
 14:11:54.531617 special request received, no persistency
 14:11:54.531695 ====> Client disconnect 0
=== End of file http_server.log
=== Start of file http_verify.log
 * !!! WARNING !!
 * This is a debug build of libcurl, do not use in production.
 * alloc connection, bits.close=0
 * setup connection, bits.close=0
 * setup connection, bits.close=0
 * new connection, bits.close=0
 *   Trying 127.0.0.1:64407...
 * Established connection to 127.0.0.1 (127.0.0.1 port 64407) from 127.0.0.1 port 52514
 * using HTTP/1.x
 * sending last upload chunk of 97 bytes
 * Curl_xfer_send(len=97, eos=1) -> 0, 97
 > GET /verifiedserver HTTP/1.1
 > Host: 127.0.0.1:64407
 > User-Agent: curl/8.18.0-DEV
 > Accept: */*
 >
 * Request completely sent off
 < HTTP/1.1 200 OK
 < Content-Length: 19
 <
 { [19 bytes data]
 * Connection #0 to host 127.0.0.1:64407 left intact
=== End of file http_verify.log
=== Start of file http_verify.out
 WE ROOLZ: 4200364
=== End of file http_verify.out
=== Start of file server.cmd
 Testnum 1467
=== End of file server.cmd
=== Start of file server.response
 HTTP/1.1 200 OK
 Content-Length: 19
 WE ROOLZ: 4200364
=== End of file server.response
=== Start of file socks2_server.log
 14:11:54.597017 Running unix version
 14:11:54.597943 Listening on Unix socket D:/a/_temp/msys64/tmp/curl-socksd-xe3LMbVY
 14:11:54.598142 Wrote pid 4195104 to log/1/server/socks2_server.pid
=== End of file socks2_server.log
=== Start of file stderr1467
   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                  Dload  Upload   Total   Spent    Left  Speed

   0      0   0      0   0      0      0      0  --:--:-- --:--:-- --:--:--      0
 curl: (7) Failed to connect to 127.0.0.1 port 64407 via localhost/tmp/curl-socksd-xe3LMbVY after 4 ms: Could not connect to server
=== End of file stderr1467
=== Start of file trace1467
 14:11:55.693000 * !!! WARNING !!
 14:11:55.693000 * This is a debug build of libcurl, do not use in production.
 14:11:55.693000 * alloc connection, bits.close=0
 14:11:55.693000 * setup connection, bits.close=0
 14:11:55.693000 * setup connection, bits.close=0
 14:11:55.693000 * new connection, bits.close=0
 14:11:55.693000 *   Trying /tmp/curl-socksd-xe3LMbVY:0...
 14:11:55.693000 * Immediate connect fail for /tmp/curl-socksd-xe3LMbVY: Network down
 14:11:55.693000 * Failed to connect to 127.0.0.1 port 64407 via localhost/tmp/curl-socksd-xe3LMbVY after 4 ms: Could not connect to server
 14:11:55.693000 * closing connection #0
=== End of file trace1467
test 1474...[--proto -all disables all protocols]
-------em-- OK (1418 out of 1818, remaining: 01:15, took 0.437s, duration: 04:27)
test 1468...[HTTP GET with hostname using SOCKS5h via Unix sockets]

 1468: protocol FAILED!
 There was no content at all in the file log/3/server.input.
 Server glitch? Total curl failure? Returned: 7
== Contents of files in the log/3/ directory after test 1468
=== Start of file commands.log
 ../src/curl.exe -q --output log/3/curl1468.out  --include --trace-ascii log/3/trace1468 --trace-time http://this.is.a.host.name:64405/1468 --proxy socks5h://localhost/tmp/curl-socksd-YnbvRo98 > log/3/stdout1468 2> log/3/stderr1468
=== End of file commands.log
=== Start of file http_server.log
 14:11:54.529551 ====> Client connect
 14:11:54.529749 accept_connection 268 returned 608
 14:11:54.529878 accept_connection 268 returned 0
 14:11:54.530268 Read 97 bytes
 14:11:54.530361 Process 97 bytes request
 14:11:54.530613 Got request: GET /verifiedserver HTTP/1.1
 14:11:54.530826 Are-we-friendly question received
 14:11:54.530987 Wrote request (97 bytes) input to log/3/server.input
 14:11:54.531124 Identifying ourselves as friends
 14:11:54.531384 Response sent (58 bytes) and written to log/3/server.response
 14:11:54.531498 special request received, no persistency
 14:11:54.531566 ====> Client disconnect 0
=== End of file http_server.log
=== Start of file http_verify.log
 * !!! WARNING !!
 * This is a debug build of libcurl, do not use in production.
 * alloc connection, bits.close=0
 * setup connection, bits.close=0
 * setup connection, bits.close=0
 * new connection, bits.close=0
 *   Trying 127.0.0.1:64405...
 * Established connection to 127.0.0.1 (127.0.0.1 port 64405) from 127.0.0.1 port 52515
 * using HTTP/1.x
 * sending last upload chunk of 97 bytes
 * Curl_xfer_send(len=97, eos=1) -> 0, 97
 > GET /verifiedserver HTTP/1.1
 > Host: 127.0.0.1:64405
 > User-Agent: curl/8.18.0-DEV
 > Accept: */*
 >
 * Request completely sent off
 < HTTP/1.1 200 OK
 < Content-Length: 19
 <
 { [19 bytes data]
 * Connection #0 to host 127.0.0.1:64405 left intact
=== End of file http_verify.log
=== Start of file http_verify.out
 WE ROOLZ: 4197832
=== End of file http_verify.out
=== Start of file server.cmd
 Testnum 1468
=== End of file server.cmd
=== Start of file server.response
 HTTP/1.1 200 OK
 Content-Length: 19
 WE ROOLZ: 4197832
=== End of file server.response
=== Start of file socks2_server.log
 14:11:54.597034 Running unix version
 14:11:54.597968 Listening on Unix socket D:/a/_temp/msys64/tmp/curl-socksd-YnbvRo98
 14:11:54.598176 Wrote pid 4203736 to log/3/server/socks2_server.pid
=== End of file socks2_server.log
=== Start of file stderr1468
   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                  Dload  Upload   Total   Spent    Left  Speed

   0      0   0      0   0      0      0      0  --:--:-- --:--:-- --:--:--      0
 curl: (7) Failed to connect to this.is.a.host.name port 64405 via localhost/tmp/curl-socksd-YnbvRo98 after 4 ms: Could not connect to server
=== End of file stderr1468
=== Start of file trace1468
 14:11:55.693000 * !!! WARNING !!
 14:11:55.693000 * This is a debug build of libcurl, do not use in production.
 14:11:55.693000 * alloc connection, bits.close=0
 14:11:55.693000 * setup connection, bits.close=0
 14:11:55.693000 * setup connection, bits.close=0
 14:11:55.693000 * new connection, bits.close=0
 14:11:55.693000 *   Trying /tmp/curl-socksd-YnbvRo98:0...
 14:11:55.693000 * Immediate connect fail for /tmp/curl-socksd-YnbvRo98: Network down
 14:11:55.693000 * Failed to connect to this.is.a.host.name port 64405 via localhost/tmp/curl-socksd-YnbvRo98 after 4 ms: Could not connect to server
 14:11:55.693000 * closing connection #0
=== End of file trace1468
test 1477...[Verify that error codes in headers and libcurl-errors.3 are in sync]
s------e--- OK (1421 out of 1818, remaining: 01:14, took 0.140s, duration: 04:27)
test 1470...[HTTPS GET with hostname using SOCKS5h via Unix sockets]

 1470: protocol FAILED!
 There was no content at all in the file log/5/server.input.
 Server glitch? Total curl failure? Returned: 7
== Contents of files in the log/5/ directory after test 1470
=== Start of file commands.log
 ../src/curl.exe -q --output log/5/curl1470.out  --include --trace-ascii log/5/trace1470 --trace-time https://this.is.a.host.name:65483/1470 --insecure --proxy socks5h://localhost/tmp/curl-socksd-el7LUslB > log/5/stdout1470 2> log/5/stderr1470
=== End of file commands.log
=== Start of file http_server.log
 14:11:54.973870 ====> Client connect
 14:11:54.974003 accept_connection 260 returned 560
 14:11:54.974085 accept_connection 260 returned 0
 14:11:54.974160 Read 97 bytes
 14:11:54.974227 Process 97 bytes request
 14:11:54.974297 Got request: GET /verifiedserver HTTP/1.1
 14:11:54.974362 Are-we-friendly question received
 14:11:54.974476 Wrote request (97 bytes) input to log/5/server.input
 14:11:54.974579 Identifying ourselves as friends
 14:11:54.974813 Response sent (58 bytes) and written to log/5/server.response
 14:11:54.974889 special request received, no persistency
 14:11:54.974944 ====> Client disconnect 0
=== End of file http_server.log
=== Start of file https_verify.log
 * !!! WARNING !!
 * This is a debug build of libcurl, do not use in production.
 * alloc connection, bits.close=0
 * setup connection, bits.close=0
 * setup connection, bits.close=0
 * new connection, bits.close=0
 *   Trying 127.0.0.1:65483...
 * GnuTLS priority: NORMAL:-ARCFOUR-128:-CTYPE-ALL:+CTYPE-X509:-VERS-SSL3.0:-VERS-TLS-ALL:+VERS-TLS1.3:+VERS-TLS1.2
 * ALPN: curl offers h2,http/1.1
 * SSL Trust: peer verification disabled
 * SSL connection using TLS1.3 / ECDHE_RSA_AES_256_GCM_SHA384
 *   SSL certificate verification SKIPPED
 *   SSL certificate expiration date OK
 *   SSL certificate activation date OK
 *   SSL certificate status verification SKIPPED
 *   common name: localhost (does not match '127.0.0.1')
 *   certificate public key: EC/ECDSA
 *   certificate version: #3
 *   subject: C=NN,O=Edel curl Arctic Illudium Research Cloud,CN=localhost
 *   start date: Wed, 03 Dec 2025 14:06:46 GMT
 *   expire date: Tue, 29 Sep 2026 14:06:46 GMT
 *   issuer: C=NN,O=Edel curl Arctic Illudium Research Cloud,CN=Northern Nowhere Trust Anchor
 * ALPN: server did not agree on a protocol. Uses default.
 * Established connection to 127.0.0.1 (127.0.0.1 port 65483) from 127.0.0.1 port 52518
 * using HTTP/1.x
 * sending last upload chunk of 97 bytes
 * Curl_xfer_send(len=97, eos=1) -> 0, 97
 > GET /verifiedserver HTTP/1.1
 > Host: 127.0.0.1:65483
 > User-Agent: curl/8.18.0-DEV
 > Accept: */*
 >
 * Request completely sent off
 < HTTP/1.1 200 OK
 < Content-Length: 19
 <
 { [19 bytes data]
 * Connection #0 to host 127.0.0.1:65483 left intact
=== End of file https_verify.log
=== Start of file https_verify.out
 WE ROOLZ: 4196540
=== End of file https_verify.out
=== Start of file server.cmd
 Testnum 1470
=== End of file server.cmd
=== Start of file server.response
 HTTP/1.1 200 OK
 Content-Length: 19
 WE ROOLZ: 4196540
=== End of file server.response
=== Start of file socks2_server.log
 14:11:55.043373 Running unix version
 14:11:55.044269 Listening on Unix socket D:/a/_temp/msys64/tmp/curl-socksd-el7LUslB
 14:11:55.044474 Wrote pid 4196296 to log/5/server/socks2_server.pid
=== End of file socks2_server.log
=== Start of file stderr1470
   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                  Dload  Upload   Total   Spent    Left  Speed

   0      0   0      0   0      0      0      0  --:--:-- --:--:-- --:--:--      0
 curl: (7) Failed to connect to this.is.a.host.name port 65483 via localhost/tmp/curl-socksd-el7LUslB after 3 ms: Could not connect to server
=== End of file stderr1470
=== Start of file trace1470
 14:11:56.178000 * !!! WARNING !!
 14:11:56.178000 * This is a debug build of libcurl, do not use in production.
 14:11:56.178000 * alloc connection, bits.close=0
 14:11:56.178000 * setup connection, bits.close=0
 14:11:56.178000 * setup connection, bits.close=0
 14:11:56.178000 * new connection, bits.close=0
 14:11:56.178000 *   Trying /tmp/curl-socksd-el7LUslB:0...
 14:11:56.178000 * Immediate connect fail for /tmp/curl-socksd-el7LUslB: Network down
 14:11:56.178000 * Failed to connect to this.is.a.host.name port 65483 via localhost/tmp/curl-socksd-el7LUslB after 3 ms: Could not connect to server
 14:11:56.178000 * closing connection #0
=== End of file trace1470

[...]

FAIL 1467: 'HTTP GET via SOCKS5 proxy via Unix sockets' HTTP, HTTP GET, SOCKS5, UnixSockets
FAIL 1468: 'HTTP GET with hostname using SOCKS5h via Unix sockets' HTTP, HTTP GET, SOCKS5, SOCKS5h, UnixSockets
FAIL 1470: 'HTTPS GET with hostname using SOCKS5h via Unix sockets' HTTPS, HTTP, HTTP GET, SOCKS5, SOCKS5h, UnixSockets
```

https://github.com/curl/curl/actions/runs/19896583933/job/57028545111?pr=19812
…ll operating systems"

This reverts commit 9397e3b.

Double leading slash breaks Cygwin and MSYS2 (slightly differently):
https://github.com/curl/curl/actions/runs/19928374178/job/57133768163?pr=19812

This is how it looked before:
https://github.com/curl/curl/actions/runs/19898592049
This reverts commit 4b57337.

This would likely need passing specially formatted filenames
depending on platform.

It also doesn't fix curl touching up the URL/filename later
and breaking it on native Windows:

 ../src/Debug/curl.exe -q --output log/3/curl1467.out  --include --trace-ascii log/3/trace1467 --trace-time --socks5 localhost/D:/a/curl/curl/bld/tests/log/3/server/socks-uds http://127.0.0.1:58215/1467 > log/3/stdout1467 2> log/3/stderr1467
[...]
 12:14:08.042000 * !!! WARNING !!
 12:14:08.042000 * This is a debug build of libcurl, do not use in production.
 12:14:08.042000 * alloc connection, bits.close=0
 12:14:08.042000 * Unsupported proxy syntax in 'localhost\D;A:\curl\curl\bld\tests\log\3\server\socks-uds': Port number was not a decimal number between 0 and 65535

https://github.com/curl/curl/actions/runs/19928374178/job/57133768233?pr=19812
@vszakats vszakats marked this pull request as ready for review December 4, 2025 18:56
@vszakats vszakats changed the title sws: fix binding to Unix socket on Windows sws: fix binding to unix socket on Windows Dec 4, 2025
@vszakats vszakats closed this in f97e62f Dec 4, 2025
@vszakats vszakats deleted the wunixsocks branch December 4, 2025 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

2 participants