Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

set linger to 0 for both inbound and outbound connections #36

Merged
merged 3 commits into from
Apr 4, 2019

Conversation

Stebalien
Copy link
Member

@Stebalien Stebalien commented Apr 4, 2019

This causes us to send RST packets instead of FIN packets when closing connections and means connections immediately enter the "reset" state instead of entering the TIME-WAIT state.

Importantly, this means we can immediately reuse the 5-tuple and reconnect.

(blocked on a go-reuseport-transport release: libp2p/go-reuseport-transport#14)

@ghost ghost assigned Stebalien Apr 4, 2019
@ghost ghost added the status/in-progress In progress label Apr 4, 2019
Stebalien added a commit to libp2p/go-reuseport-transport that referenced this pull request Apr 4, 2019
We should do this from
go-tcp-transport (libp2p/go-tcp-transport#36), not here,
as setting linger to 0 will cause us to send RST packets instead of nicely
closing connections.

Also, document why we need the fallback dialer.
@Stebalien Stebalien requested a review from anacrolix April 4, 2019 02:34
func tryLinger(conn net.Conn, sec int) {
if lingerConn, ok := conn.(interface {
SetLinger(int) error
}); ok {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a handful, maybe worth naming the linger interface.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bah!

This causes us to send RST packets instead of FIN packets when closing
connections and means connections immediately enter the "reset" state instead of
entering the TIME-WAIT state.

Importantly, this means we can immediately reuse the 5-tuple and reconnect.
@Stebalien Stebalien marked this pull request as ready for review April 4, 2019 07:13
@Stebalien Stebalien merged commit 42717ef into master Apr 4, 2019
@ghost ghost removed the status/in-progress In progress label Apr 4, 2019
@Stebalien Stebalien deleted the fix/linger branch April 4, 2019 07:23
marten-seemann pushed a commit to libp2p/go-libp2p that referenced this pull request Apr 26, 2022
We should do this from
go-tcp-transport (libp2p/go-tcp-transport#36), not here,
as setting linger to 0 will cause us to send RST packets instead of nicely
closing connections.

Also, document why we need the fallback dialer.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants