Skip to content

net: using File methods on Conn/Listener/PacketConn disables non-blocking I/O and runtime-integrated network poller's deadline features #9420

Closed
@jbardin

Description

@jbardin

Calling a network connection's File() method prevents deadlines from working.

This won't timeout correctly:

c, _ := net.ListenUDP("udp", &net.UDPAddr{IP: net.IP{127, 0, 0, 1}, Port: 9999})
fmt.Println("timing out in 1s")
c.SetReadDeadline(time.Now().Add(time.Second))

// calling File() removes the ability to use deadlines
_, _ = c.File()

buf := make([]byte, 1024)
_, e := c.Read(buf)
fmt.Println(e)

It would be nice if deadlines still worked when a socket is in blocking mode, but if it's not possible this should at least be documented.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions