Skip to content

Commit 60e3ebb

Browse files
fraenkelianlancetaylor
authored andcommitted
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 68c1028 commit 60e3ebb

File tree

4 files changed

+5
-15
lines changed

4 files changed

+5
-15
lines changed

src/net/fd_unix.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,5 @@ func (fd *netFD) dup() (f *os.File, err error) {
309309
return nil, err
310310
}
311311

312-
// We want blocking mode for the new fd, hence the double negative.
313-
// This also puts the old fd into blocking mode, meaning that
314-
// I/O will block the thread instead of letting us use the epoll server.
315-
// Everything will still work, just with more threads.
316-
if err = fd.pfd.SetBlocking(); err != nil {
317-
return nil, os.NewSyscallError("setnonblock", err)
318-
}
319-
320312
return os.NewFile(uintptr(ns), fd.name()), nil
321313
}

src/net/net.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,13 @@ func (c *conn) SetWriteBuffer(bytes int) error {
281281
return nil
282282
}
283283

284-
// File sets the underlying os.File to blocking mode and returns a copy.
284+
// File returns a copy of the underlying os.File
285285
// It is the caller's responsibility to close f when finished.
286286
// Closing c does not affect f, and closing f does not affect c.
287287
//
288288
// The returned os.File's file descriptor is different from the connection's.
289289
// Attempting to change properties of the original using this duplicate
290290
// may or may not have the desired effect.
291-
//
292-
// On Unix systems this will cause the SetDeadline methods to stop working.
293291
func (c *conn) File() (f *os.File, err error) {
294292
f, err = c.fd.dup()
295293
if err != nil {

src/net/tcpsock.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ func (l *TCPListener) SetDeadline(t time.Time) error {
292292
return nil
293293
}
294294

295-
// File returns a copy of the underlying os.File, set to blocking
296-
// mode. It is the caller's responsibility to close f when finished.
295+
// File returns a copy of the underlying os.File.
296+
// It is the caller's responsibility to close f when finished.
297297
// Closing l does not affect f, and closing f does not affect l.
298298
//
299299
// The returned os.File's file descriptor is different from the

src/net/unixsock.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ func (l *UnixListener) SetDeadline(t time.Time) error {
286286
return nil
287287
}
288288

289-
// File returns a copy of the underlying os.File, set to blocking
290-
// mode. It is the caller's responsibility to close f when finished.
289+
// File returns a copy of the underlying os.File.
290+
// It is the caller's responsibility to close f when finished.
291291
// Closing l does not affect f, and closing f does not affect l.
292292
//
293293
// The returned os.File's file descriptor is different from the

0 commit comments

Comments
 (0)