wasi: sockets, use Conn.Control on Unix, too; align to Windows #1892
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 throughConn.Control
. This in turn allows to share a lot more of the original code, further cleaning up the implementation.