From 4eb467a7243473a69ad8bb95b1812af316198c62 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Wed, 23 Jun 2021 07:31:05 -0600 Subject: [PATCH] Skip SetKeepAlivePeriod call on OpenBSD 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. --- p2p/transport/tcp/tcp.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/p2p/transport/tcp/tcp.go b/p2p/transport/tcp/tcp.go index 3e1766370..4dbc7260f 100644 --- a/p2p/transport/tcp/tcp.go +++ b/p2p/transport/tcp/tcp.go @@ -3,6 +3,7 @@ package tcp import ( "context" "net" + "runtime" "time" logging "github.com/ipfs/go-log" @@ -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) + } } }