Skip to content

Commit

Permalink
Skip SetKeepAlivePeriod call on OpenBSD
Browse files Browse the repository at this point in the history
OpenBSD does not have a user-settable per-socket TCP keepalives. This changes
tryKeepAlive to skip attempting set it when on OpenBSD.

  https://github.com/golang/go/blob/master/src/net/tcpsockopt_openbsd.go#L13-L14

This prevents thousands of `log.Errorf("Failed set keepalive period: %s",
err)`'s from happening.
  • Loading branch information
qbit committed Jun 23, 2021
1 parent ed9ea79 commit 4eb467a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions p2p/transport/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tcp
import (
"context"
"net"
"runtime"
"time"

logging "github.com/ipfs/go-log"
Expand Down Expand Up @@ -41,8 +42,11 @@ func tryKeepAlive(conn net.Conn, keepAlive bool) {
log.Errorf("Failed to enable TCP keepalive: %s", err)
return
}
if err := keepAliveConn.SetKeepAlivePeriod(keepAlivePeriod); err != nil {
log.Errorf("Failed set keepalive period: %s", err)

if runtime.GOOS != "openbsd" {
if err := keepAliveConn.SetKeepAlivePeriod(keepAlivePeriod); err != nil {
log.Errorf("Failed set keepalive period: %s", err)
}
}
}

Expand Down

0 comments on commit 4eb467a

Please sign in to comment.