Skip to content

x/net/ipv4: NewPacketConn requires net.Conn but this is not documented #47491

@AudriusButkevicius

Description

@AudriusButkevicius

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 satisfies net.PacketConn but not net.Conn.

The code in NewPacketConn does a type assertion to net.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 a conn, 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 the ok() checks of the genericOpt, dgramOpt and payloadHandler so that the connection returned would just return errInvalidConn for any operation.

Alternative would be to document that ipv4.NewPacketConn also needs to satisfy net.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

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions