-
Notifications
You must be signed in to change notification settings - Fork 18.1k
x/net: ReadBatch fails if conn passed to ipv4.New{Packet}Conn is not a net.{TCP/UDP}Conn #42444
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
While one could argue that This is easy to accomplish, since
func NewConn(c net.Conn) (*Conn, error) {
var err error
var cc Conn
if tcpConn, ok := c.(interface {
SyscallConn() (syscall.RawConn, error)
SetLinger() error
}); ok {
cc.network = "tcp"
cc.c, err = tcpConn.SyscallConn()
} else if udpConn, ok := c.(interface {
SyscallConn() (syscall.RawConn, error)
ReadMsgUDP(b, oob []byte) (n, oobn, flags int, addr *net.UDPAddr, err error)
}); ok {
cc.network = "udp"
cc.c, err = udpConn.SyscallConn()
} else if ipConn, ok := := c.(interface {
SyscallConn() (syscall.RawConn, error)
ReadMsgIP(b, oob []byte) (n, oobn, flags int, addr *net.IPAddr, err error)
}); ok {
cc.network = "ip"
cc.c, err = ipConn.SyscallConn()
} else
return nil, errors.New("unknown connection type")
}
if err != nil {
return nil, err
}
return &cc, nil
} |
Suggested fix: https://go-review.googlesource.com/c/net/+/271927. |
Change https://golang.org/cl/271927 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
When passing a wrapped connection to
ipv4.NewPacketConn()
, calls toReadBatch()
will fail with aninvalid connection
error:This is unexpected, as
NewPacketConn
accepts anet.PacketConn
, and does not require anet.UDPConn
.Analogously for
NewConn
with anet.TCPConn
.The problem here is that the constructor calls
socket.NewConn
, which does a type assertion: https://github.com/golang/net/blob/ff519b6c91021e6316e1df005bc19f266994ddda/internal/socket/rawconn.go#L21-L41, which will fail if theUPDConn
is wrapped.What did you expect to see?
I expected
ReadBatch
to work.What did you see instead?
See above.
The text was updated successfully, but these errors were encountered: