x/net/ipv4: NewPacketConn requires net.Conn but this is not documented #47491
Labels
Documentation
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?tip
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?GOOS=windows
GOARCH=amd64
What did you do?
Called
ipv4.NewPacketConn
with something that satisfiesnet.PacketConn
but notnet.Conn
.The code in
NewPacketConn
does a type assertion tonet.Conn
, without checking if the type satisfies it.It's not documented that the parameter also needs to satisfy
net.Conn
.See: https://github.com/golang/net/blob/master/ipv4/endpoint.go#L102-L110
Ideally
NewPacketConn
would return aconn, err
, but that would be a breaking change, in which case the second best option would be for it to return a connection that fails theok()
checks of thegenericOpt
,dgramOpt
andpayloadHandler
so that the connection returned would just returnerrInvalidConn
for any operation.Alternative would be to document that
ipv4.NewPacketConn
also needs to satisfynet.Conn
.What did you expect to see?
A connection returned, potentially one that returns an error on every operation.
What did you see instead?
A panic
The text was updated successfully, but these errors were encountered: