Skip to content
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

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

Closed
jbardin opened this issue Dec 22, 2014 · 4 comments

Comments

@jbardin
Copy link
Contributor

jbardin commented Dec 22, 2014

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.

@mikioh mikioh changed the title net: using a conn's File() method breaks deadlines net: using File methods on Conn/PacketConn disable non-blocking I/O and runtime-integrated network poller's deadline features Dec 22, 2014
@mikioh
Copy link
Contributor

mikioh commented Dec 22, 2014

It's documented, and we provide FileConn/FileListener/FilePacketConn functions.

@mikioh mikioh closed this as completed Dec 22, 2014
@mikioh mikioh changed the title net: using File methods on Conn/PacketConn disable non-blocking I/O and runtime-integrated network poller's deadline features net: using File methods on Conn/Listener/PacketConn disable non-blocking I/O and runtime-integrated network poller's deadline features Dec 22, 2014
@jbardin
Copy link
Contributor Author

jbardin commented Dec 23, 2014

I understand, but I think it could use a little more precise wording in the documentation as to what "sets the underlying os.File to blocking mode" implies. I wouldn't expect the runtime to start setting RCVTIMEO and SNDTIMEO, but I also couldn't find an stanza stating exactly what the behavior would be.

@mikioh mikioh changed the title net: using File methods on Conn/Listener/PacketConn disable non-blocking I/O and runtime-integrated network poller's deadline features net: using File methods on Conn/Listener/PacketConn disables non-blocking I/O and runtime-integrated network poller's deadline features Dec 23, 2014
@mikioh
Copy link
Contributor

mikioh commented Dec 23, 2014

use a little more precise wording in the documentation

@jbardin, feel free to send a patch. thanks.
https://golang.org/doc/contribute.html

@golang golang locked and limited conversation to collaborators Jun 25, 2016
@mikioh
Copy link
Contributor

mikioh commented Apr 20, 2018

See #24942.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants