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

internal/poll: sending a zero-byte-payload UDP packet on Windows is a no-op #26668

Closed
delthas opened this issue Jul 28, 2018 · 7 comments
Closed

internal/poll: sending a zero-byte-payload UDP packet on Windows is a no-op #26668

delthas opened this issue Jul 28, 2018 · 7 comments

Comments

@delthas
Copy link

@delthas delthas commented Jul 28, 2018

What version of Go are you using (go version)?

go version go1.10.3 windows/amd64

Does this issue reproduce with the latest release?

Yes, 1.10.3 is the latest release.

What operating system and processor architecture are you using (go env)?

(Irrelevant)

set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\delthas\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\delthas\go
set GORACE=
set GOROOT=C:\Programs\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Programs\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\delthas\AppData\Local\Temp\go-build595515002=/tmp/go-build -gno-record-gcc-switches

What did you do?

Minimal working example: https://play.golang.org/p/aFzB44u87fO
This playground example only works on Linux (so it works in the playground). Run it on a Windows machine to see the bug.

On Windows, send a zero-length-payload UDP packet and try to read it.

What did you expect to see?

I would expect to see the same behaviour as on Linux, which is that the packet is received.

What did you see instead?

The packet is not received and the read timeouts.


This bug is due to a payload length check in internal/poll/fd_windows.go that returns early before any WSAsendto call is done.

This check was added in the first implementation of this method in this commit in 2010.

There is a test supposed to cover this specific case: TestUDPZeroBytePayload in net/udpsock_test.go but it is "broken" on Windows: the test sends a zero-byte-payload and reads it with ReadFrom, and then sends another packet and reads it with Read. A comment reads that for the former case the ReadFrom should return with err == nil, and in the latter case the Read should return with a timeout error, however it does not actually check if this is the case and accepts timeouts for both cases. And on Windows, the two cases return with a timeout error, rather than the expected behaviour, because no actual packet is sent because of the check linked above.

A simple fix for this is to remove the check, and update the test to actually check if there is no timeout error in the ReadFrom case.

Can I open a pull request to fix this?

@delthas delthas changed the title Sending a zero-byte-payload UDP packet on Windows is a no-op internal/poll: Sending a zero-byte-payload UDP packet on Windows is a no-op Jul 28, 2018
@delthas delthas changed the title internal/poll: Sending a zero-byte-payload UDP packet on Windows is a no-op internal/poll: sending a zero-byte-payload UDP packet on Windows is a no-op Jul 28, 2018
@alexbrainman
Copy link
Member

@alexbrainman alexbrainman commented Jul 29, 2018

Can I open a pull request to fix this?

Please, do.

It would be nice, if you send change to fix TestUDPZeroBytePayload first - it is OK to break the test on Windows - just skip test on Windows.

And then send change to fix windows internal/poll.FD.WriteTo - together with making TestUDPZeroBytePayload run again.

I am not sure how close we are to releasing go1.11, so your changes might have to wait for couple of weeks. But I suggest you send the change now - and see what happens.

Thank you.

Alex

@silbinarywolf
Copy link
Contributor

@silbinarywolf silbinarywolf commented Sep 1, 2018

If nobody wants to claim this, I'm able to make time for this tomorrow. I predominantly develop on Windows, so the friction of testing this sort of bug is low.

@delthas Are you currently working on this?

@delthas
Copy link
Author

@delthas delthas commented Sep 1, 2018

silbinarywolf added a commit to silbinarywolf/go that referenced this issue Sep 2, 2018
silbinarywolf added a commit to silbinarywolf/go that referenced this issue Sep 2, 2018
silbinarywolf added a commit to silbinarywolf/go that referenced this issue Sep 2, 2018
silbinarywolf added a commit to silbinarywolf/go that referenced this issue Sep 2, 2018
silbinarywolf added a commit to silbinarywolf/go that referenced this issue Sep 2, 2018
@gopherbot
Copy link

@gopherbot gopherbot commented Sep 2, 2018

Change https://golang.org/cl/132780 mentions this issue: net: fix TestUDPZeroBytePayload for windows

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 2, 2018

Change https://golang.org/cl/132781 mentions this issue: net: fix zero-byte payload bug in WriteTo() for windows

@odeke-em
Copy link
Member

@odeke-em odeke-em commented Sep 3, 2018

@silbinarywolf thank you for working on this!

Since Go1.11 was released a month after @alexbrainman's suggestion in #26668 (comment), I don't think we need to disable the test anymore and you can instead send the single CL as you've done in https://golang.org/cl/132781.

silbinarywolf added a commit to silbinarywolf/go that referenced this issue Sep 3, 2018
@silbinarywolf
Copy link
Contributor

@silbinarywolf silbinarywolf commented Sep 3, 2018

@odeke-em Fair enough. I wasn't sure how to close the CL so I added a comment / edited it saying to ignore it in favour of the single CL.

Cheers!

@gopherbot gopherbot closed this in 3e5b5d6 Sep 6, 2018
@golang golang locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

6 participants
You can’t perform that action at this time.