Skip to content

fix: set TCPMaxRetries to 5 for reasonable timeouts on send #61

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

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions wgengine/netstack/netstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ const (
// CUBIC congestion control is the default in Windows, Linux, and MacOS, and generally achieves
// better throughput on large, long networks.
congestionControlCubic = "cubic"
// maxRetries is the maximum number of retransmissions that the TCP stack should undertake for
// unacked TCP segments, that is, when we are trying to send TCP data and the other side is
// unresponsive. It does not affect TCP operation while both sides are idle. The retry timeout
// has a minimum of 200ms and maximum of 120s, and grows exponentially when the other side is
// unresponsive. The default maxRetries in gVisor is 15, which means in practice over ten
// minutes of unresponsiveness before we time out. Setting to 5 should time out in 15-30s,
// depending on the latency of the connection. In Coder's system we depend on Wireguard as the
// underlay, which retries handshakes on a 5s timer, so we don't want to shorten the timeout
// less than 15s or so, to give us several chances to re-establish a Wireguard session after
// idling.
maxRetries = 5
)

// Create creates and populates a new Impl.
Expand Down Expand Up @@ -227,6 +238,11 @@ func Create(logf logger.Logf, tundev *tstun.Wrapper, e wgengine.Engine, mc *magi
if tcpipErr != nil {
return nil, fmt.Errorf("could not set congestion control: %v", tcpipErr)
}
retries := tcpip.TCPMaxRetriesOption(maxRetries)
tcpipErr = ipstack.SetTransportProtocolOption(tcp.ProtocolNumber, &retries)
if tcpipErr != nil {
return nil, fmt.Errorf("could not set max retries: %v", tcpipErr)
}

linkEP := NewEndpoint(512, tstun.DefaultMTU(), "")
if tcpipProblem := ipstack.CreateNIC(nicID, linkEP); tcpipProblem != nil {
Expand Down
Loading