Skip to content

gh-77589: Add unix domain socket for Windows #137420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

aisk
Copy link
Member

@aisk aisk commented Aug 5, 2025

Didn't add asyncio support in this PR to avoid too many code changes and keep the review process simpler.

PC/pyconfig.h Outdated
@@ -671,6 +671,9 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
/* Define if you have the <sys/un.h> header file. */
/* #define HAVE_SYS_UN_H 1 */

/* Define if you have the <afunix.h> header file. */
#define HAVE_AFUNIX_H 1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a question for how to detect if the header file exists.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by check #if defined(NTDDI_WIN10_RS4) && (NTDDI_VERSION >= NTDDI_WIN10_RS4).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#if defined(NTDDI_WIN10_RS4) && (NTDDI_VERSION >= NTDDI_WIN10_RS4) did'nt work because NTDDI_VERSION is defined in PC\pyconfig.h with hard code value NTDDI_WIN10 which is lesser than NTDDI_WIN10_RS4.

@aisk aisk changed the title gh-77589: Windows unix socket gh-77589: Add unix domain socket for Windows Aug 5, 2025
@aisk aisk requested a review from gpshead as a code owner August 5, 2025 16:12
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of skipping some tests, would not be worth to test a Windows specific behavior?

Some tests can currently be skipped on Windows, but they may work after adding support of AF_UNIX. Please check all currently skipped tests for socket and multiprocessing.

Comment on lines +6232 to +6233
@unittest.skipIf(sys.platform == 'win32',
'Windows allow bind on empty path')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not we test that it does not fail on Windows?

Comment on lines +6191 to +6192
@unittest.skipIf(sys.platform == 'win32',
'Windows will raise Error if is not bound')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not we test that it raises Error if is not bound?

@@ -2747,6 +2747,7 @@ def test_is_socket_false(self):
@unittest.skipIf(
is_wasi, "Cannot create socket on WASI."
)
@unittest.skipIf(sys.platform=='win32', "didn't work on Windows")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does not work? Should not we have a test for this?

@@ -215,6 +215,7 @@ def test_devices(self):
break

@socket_helper.skip_unless_bind_unix_socket
@unittest.skipIf(sys.platform=='win32', "didn't work on Windows")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not we add a test for this?

@serhiy-storchaka serhiy-storchaka requested a review from zooba August 5, 2025 18:54
@serhiy-storchaka
Copy link
Member

It seems that the previous attempt did have more changes in the socket and socketserver modules. Are they no longer relevant?

@aisk
Copy link
Member Author

aisk commented Aug 6, 2025

It seems that the previous attempt did have more changes in the socket and socketserver modules. Are they no longer relevant?

The previous attempt modified the socketpair function in the socket module to use AF_UNIX by default on Windows, so it would introduce more changes. I'd like to keep the current behavior to reduce code changes in one PR and compatibility break risk, and we can change it in the future.

The change in socketserver in the previous attempt is mainly because in asyncio's test case, it tries to create an HTTP server over unix domain sockets. On Windows, currently AF_UNIX doesn't support reuse_address, so there needs to be this modification. I changed the test to disable reuse_address on Windows with AF_UNIX. But I think the previous attempt is the right way because users can encounter this issue too. Will update this later today. Thank you for the review!

@aisk aisk requested a review from vsajip as a code owner August 7, 2025 15:54
@aisk aisk marked this pull request as draft August 9, 2025 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants