-
Notifications
You must be signed in to change notification settings - Fork 18k
net: ListenMulticastUDP fails if Ethernet is unplugged #70132
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
Comments
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
@neild @ianlancetaylor Are these changes that you would be amenable to? We'd be willing to contribute the fixes. In particular, we want to make two changes. First, fix Second, fix Lines 69 to 71 in 3730814
|
@neild @ianlancetaylor following up |
I think you know a lot more about this than I do. Based on the ip(7) man page, it seems clear that on Linux And I agree that it does appear that So your proposed changes sound reasonable to me. I wonder if there is any way to add a test to the net package for them. Thanks. |
Change https://go.dev/cl/644375 mentions this issue: |
Go version
go version 1.22.8 linux/amd64
Output of
go env
in your module/workspace:What did you do?
My VirtualBox VM has two Ethernet interfaces - enp0s3 and enp0s8. I have noticed a few issues with how
net.ListenMulticastUDP
works, all seemingly due to how it doesIP_ADD_MEMBERSHIP
.What did you see happen?
If I run the above code after telling VirtualBox to disconnect the cable from enp0s3, I get:
I have tracked the error down to this specific call.
go/src/net/sockoptip_posix.go
Line 19 in 6d39245
Meanwhile, if I change the sample program to bind to enp0s8 instead, and I tell VirtualBox to disconnect enp0s8 (and re-connect enp0s3), what actually happens is it ends up bound to enp0s3, as confirmed by
netstat
.I believe what is happening is that
setIPv4MreqToInterface
ends up leavingmreq.Interface
as 0.0.0.0 because the interface in question has no IP addresses when the cable is unplugged. Since enp0s3 is my default interface:It is worth noting we have also observed this issue in "the real world" (i.e., not in a VM) -
net.ListenMulticastUDP
will hard fail if the kernel has no route table entry at that moment, which can happen if the Ethernet cable happens to be unplugged.My experiments show that using
SetsockoptIPMreqn
instead ofSetsockoptIPMreq
to doIP_ADD_MEMBERSHIP
(and passing the interface index instead of its IP address) seems to make it work as expected in both cases.I also noticed that x/net uses
MCAST_JOIN_GROUP
instead ofIP_ADD_MEMBERSHIP
.https://github.com/golang/net/blob/f35fec92ec9213ee211cf45f451a5970386f7978/ipv4/sys_linux.go#L34
However, that sockopt is entirely undocumented and seems to be an internal detail of the kernel.
What did you expect to see?
I expected
net.ListenMulticastUDP
to work as advertised regardless of the state of the Ethernet cable.In particular, on Linux it should use
SetsockoptIPMreqn
so that it always does the right thing. On non-Linux, it should fail if anet.Interface
was provided and the interface in question has no IP address.The text was updated successfully, but these errors were encountered: