Skip to content
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

wasi: sockets, use Conn.Control on Unix, too; align to Windows #1892

Merged
merged 2 commits into from
Jan 2, 2024

Conversation

evacchi
Copy link
Contributor

@evacchi evacchi commented Dec 28, 2023

The current implementation of WASI sockets differs between Unix and Windows. On the Unix version, we save underlying FD to the struct, while on Windows we keep the Listener/Connection as a field, and invoke Conn.Control(func(fd)).

The reason for the difference on Windows, is that Windows won't return a valid file handle, because the Dup implementation is a no-op. However, further somewhat related testing (see #1891) highlighted that the Unix strategy does not really work: the FD that is being saved, is not really the underlying FD of the Listener/Connection struct, but rather the FD of a duplicated File.

Because the duplicate is not being saved, but only the FD, it looks like eventually the new File instance is collected, invalidating the underlying FD. This is only visible in long-running tests, where we probably give a chance to the runtime to run a GC cycle.

The implementation on main is incorrect anyway, so in this PR I am aligning the implementation strategy to the Windows version: we keep the Conn/Listener around in our own File struct, and only access the FD through Conn.Control. This in turn allows to share a lot more of the original code, further cleaning up the implementation.

@evacchi evacchi marked this pull request as ready for review December 28, 2023 15:55
@gaukas
Copy link
Contributor

gaukas commented Dec 28, 2023

Thank you, it works perfectly.

@mathetake mathetake merged commit 498d4b4 into main Jan 2, 2024
56 checks passed
@mathetake mathetake deleted the sock-unix-fd-fix branch January 2, 2024 16:20
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.

3 participants