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: document errata on SetLinger of TCPConn #7974

mikioh opened this issue May 12, 2014 · 3 comments


None yet
2 participants
Copy link

commented May 12, 2014

The linger option to TCPConn doesn't work as we expect especially "If sec > 0,
Close blocks for at most sec seconds waiting for data to be sent and acknowledged."
part because current  TCPConn.Close implementation never blocks anything instead of
retuning syscall.EWOULDBLOCK or similar.

func (fd *netFD) Close() error {
        // Unblock any I/O.  Once it all unblocks and returns,
        // so that it cannot be referring to fd.sysfd anymore,
        // the final decref will close fd.sysfd.  This should happen
        // fairly quickly, since all the I/O is non-blocking, and any
        // attempts to block in the pollDesc will return errClosing.

Other matters to be attended to;

- A conventional issue on TCP socket closing w/ lingering. When we call TCPConn.Close to
SetLinger(0) configured sockets on active-close side, TCPConn.Read on passive-close side
returns syscall.ECONNRESET or similar instead of io.EOF because lingering usually causes
sending RSTs. It really depends on underlying protocol stack implementation, though.

- Another conventional issue on TCP socket closing w/ lingering. SetLinger(sec > 0)
usually causes 2MSL close wait, SetLinger(sec > 0) configured sockets remain inside
the kernel for a short time (2MSL).

Perhaps we should encourage people not to use SetLinger and recommend to use CloseRead,
CloseWrite instead.

This comment has been minimized.

Copy link

commented May 12, 2014

Comment 1:

CL mentions this issue.

This comment has been minimized.

Copy link
Contributor Author

commented May 14, 2014

Comment 2:

This issue was closed by revision d145f0f.

Status changed to Fixed.


This comment has been minimized.

Copy link
Contributor Author

commented May 23, 2014

Comment 3:

Issue #7979 has been merged into this issue.

@golang golang locked and limited conversation to collaborators Jun 25, 2016

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.