Skip to content

Commit

Permalink
Revert "Set linger on p2p connections (ava-labs#2646)" (ava-labs#2703)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-kim authored Mar 7, 2023
1 parent c5d8cd3 commit 64d1b12
Showing 1 changed file with 0 additions and 25 deletions.
25 changes: 0 additions & 25 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ const (
TimeSinceLastMsgReceivedKey = "timeSinceLastMsgReceived"
TimeSinceLastMsgSentKey = "timeSinceLastMsgSent"
SendFailRateKey = "sendFailRate"

// lingerTimeout is the amount of time (in seconds) we allow for the
// remaining data in a connection to be flushed before forcibly closing the
// connection (TCP RST).
lingerTimeout = 15
)

var (
Expand Down Expand Up @@ -736,7 +731,6 @@ func (n *network) Dispatch() error {
n.metrics.acceptFailed.Inc()
continue
}
n.setLinger(conn)

// Note: listener.Accept is rate limited outside of this package, so a
// peer can not just arbitrarily spin up goroutines here.
Expand Down Expand Up @@ -1130,7 +1124,6 @@ func (n *network) dial(ctx context.Context, nodeID ids.NodeID, ip *trackedIP) {
)
continue
}
n.setLinger(conn)

n.peerConfig.Log.Verbo("starting to upgrade connection",
zap.String("direction", "outbound"),
Expand All @@ -1151,24 +1144,6 @@ func (n *network) dial(ctx context.Context, nodeID ids.NodeID, ip *trackedIP) {
}()
}

// setLinger sets the linger on [conn], if it is a [*net.TCPConn], to
// [lingerTimeout].
func (n *network) setLinger(conn net.Conn) {
tcpConn, ok := conn.(*net.TCPConn)
if !ok {
return
}

// If a connection is closed, we allow a grace period for the unsent
// data in the connection to be flushed before forcibly closing the
// connection (TCP RST).
if err := tcpConn.SetLinger(lingerTimeout); err != nil {
n.peerConfig.Log.Warn("failed to set no linger",
zap.Error(err),
)
}
}

// upgrade the provided connection, which may be an inbound connection or an
// outbound connection, with the provided [upgrader].
//
Expand Down

0 comments on commit 64d1b12

Please sign in to comment.