-
Notifications
You must be signed in to change notification settings - Fork 269
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 WSAPoll and GetOverlappedResult on Windows #1903
wasi: sockets, use WSAPoll and GetOverlappedResult on Windows #1903
Conversation
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
syscall.Read on a non-blocking socket will error with incorrect parameters on Windows. Signed-off-by: Gaukas Wang <[email protected]>
c3d9b7d
to
c653347
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a test case.
You can modify
wazero/internal/sysfs/sock_test.go
Line 50 in 009ee70
func TestTcpConnFile_Read(t *testing.T) { |
You can also add a unit test to readSocket
(add a test to file_test.go
, there is none currently.)
You can do either or both. Thanks!
Cancel the async read started by us if it cannot be completed immediately. Signed-off-by: Gaukas Wang <[email protected]>
Document the bug which could not be reproduced in a test case. Remove the fix applied. Signed-off-by: Gaukas Wang <[email protected]>
Signed-off-by: Gaukas Wang <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clean up the commented out bits, if the tests pass then it should be good to go!
Signed-off-by: Gaukas Wang <[email protected]>
Current
readSocket
function for WASI sockets is implemented incorrectly on Windows and WASI polling an async socket for a long time will eventually getERROR_WORKING_SET_QUOTA
(1453):A call to
GetOverlappedResult
is expected after eachERROR_IO_PENDING
returned byReadFile
and that is what's missing in the current implementation. Besides that,ReadFile
would create a background worker to keep on trying reading from the handle into thebuf
, which could result in data loss if we don't keep tracking of it. So we add a call toWSAPoll
before callingReadFile
to observe how many bytes are ready to be read.In this pull request, we modify how
readSocket
ininternal/sysfs/file_windows.go
is implemented by adding the following changes:WSAPoll
before callingReadFile
, abort ifno bytes are availableno fd is ready to be read.GetOverlappedResult
ifReadFile
returnsERROR_IO_PENDING
.Limit the read buffer's size according to how many bytes are ready to be read (see review comments)