net: calling File leaves the socket in nonblocking mode

On Unix systems, the underlying socket is no longer forced into blocking
mode.

Fixes #24942

Change-Id: I3e0c503c72df0844e30a63af298691dedacd1f46
Reviewed-on: https://go-review.googlesource.com/108297
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Michael Fraenkel 2018-04-19 17:54:29 -04:00 committed by Ian Lance Taylor
parent 68c10286c7
commit 60e3ebb9cb
4 changed files with 5 additions and 15 deletions

View File

@ -309,13 +309,5 @@ func (fd *netFD) dup() (f *os.File, err error) {
return nil, err
}
// We want blocking mode for the new fd, hence the double negative.
// This also puts the old fd into blocking mode, meaning that
// I/O will block the thread instead of letting us use the epoll server.
// Everything will still work, just with more threads.
if err = fd.pfd.SetBlocking(); err != nil {
return nil, os.NewSyscallError("setnonblock", err)
}
return os.NewFile(uintptr(ns), fd.name()), nil
}

View File

@ -281,15 +281,13 @@ func (c *conn) SetWriteBuffer(bytes int) error {
return nil
}
// File sets the underlying os.File to blocking mode and returns a copy.
// File returns a copy of the underlying os.File
// It is the caller's responsibility to close f when finished.
// Closing c does not affect f, and closing f does not affect c.
//
// The returned os.File's file descriptor is different from the connection's.
// Attempting to change properties of the original using this duplicate
// may or may not have the desired effect.
//
// On Unix systems this will cause the SetDeadline methods to stop working.
func (c *conn) File() (f *os.File, err error) {
f, err = c.fd.dup()
if err != nil {

View File

@ -292,8 +292,8 @@ func (l *TCPListener) SetDeadline(t time.Time) error {
return nil
}
// File returns a copy of the underlying os.File, set to blocking
// mode. It is the caller's responsibility to close f when finished.
// File returns a copy of the underlying os.File.
// It is the caller's responsibility to close f when finished.
// Closing l does not affect f, and closing f does not affect l.
//
// The returned os.File's file descriptor is different from the

View File

@ -286,8 +286,8 @@ func (l *UnixListener) SetDeadline(t time.Time) error {
return nil
}
// File returns a copy of the underlying os.File, set to blocking
// mode. It is the caller's responsibility to close f when finished.
// File returns a copy of the underlying os.File.
// It is the caller's responsibility to close f when finished.
// Closing l does not affect f, and closing f does not affect l.
//
// The returned os.File's file descriptor is different from the