diff --git a/client/dialer_linux.go b/client/dialer_linux.go new file mode 100644 index 0000000..fb62603 --- /dev/null +++ b/client/dialer_linux.go @@ -0,0 +1,15 @@ +//go:build linux + +package client + +import ( + "context" + "net" +) + +func netDialContextFunc(ctx context.Context, network, addr string) (net.Conn, error) { + dialer := &net.Dialer{ + KeepAlive: -1, + } + return dialer.DialContext(ctx, network, addr) +} diff --git a/client/dialer_other.go b/client/dialer_other.go new file mode 100644 index 0000000..133b967 --- /dev/null +++ b/client/dialer_other.go @@ -0,0 +1,15 @@ +//go:build !linux + +package client + +import ( + "context" + "net" +) + +func netDialContextFunc(ctx context.Context, network, addr string) (net.Conn, error) { + dialer := &net.Dialer{ + KeepAlive: -1, + } + return dialer.DialContext(ctx, network, addr) +} diff --git a/client/subscribe_ws.go b/client/subscribe_ws.go index 276a54d..6d53ae0 100644 --- a/client/subscribe_ws.go +++ b/client/subscribe_ws.go @@ -43,7 +43,12 @@ func SubscribeWS(ctx context.Context, url string, tlsConfig *tls.Config) (chan [ conn, resp, err := wsc.Connect( ctx, strings.Replace(url+"/subscribe/ws", "https", "wss", 1), - wsc.Config{TLSConfig: tlsConfig}, + wsc.Config{ + TLSConfig: tlsConfig, + NetDialContextFunc: netDialContextFunc, // this function is platform dependent. + PingPeriod: 15 * time.Minute, + PongWait: 20 * time.Minute, + }, ) if err != nil { log.Printf("unable to connect to ws (retrying): %s", err) diff --git a/go.mod b/go.mod index 47f4505..3f48680 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/spf13/cobra v1.7.0 github.com/spf13/viper v1.15.0 go.aporeto.io/tg v1.50.0 - go.aporeto.io/wsc v1.51.0 + go.aporeto.io/wsc v1.52.0 golang.design/x/clipboard v0.7.0 ) diff --git a/go.sum b/go.sum index 520ae6b..4b5fccd 100644 --- a/go.sum +++ b/go.sum @@ -738,6 +738,10 @@ go.aporeto.io/tg v1.50.0 h1:WOtzxPJpPkIx3+OBmUuZIclTZgvTrIIEg7uzstWucTk= go.aporeto.io/tg v1.50.0/go.mod h1:LkCXFWQN6LGrp4alU+qzNXoq/nkouQKsOzsjidoKbBc= go.aporeto.io/wsc v1.51.0 h1:xbbsfRGtUWAqTiT9ubK6TKi2+nABNf656XxnEweynRM= go.aporeto.io/wsc v1.51.0/go.mod h1:0gL/S3uPkS4f3q7/lXF5Hlt804T0d9EhgOSYJkHUbVo= +go.aporeto.io/wsc v1.51.1-0.20230516221449-e7ab6eb42d60 h1:amX4r9ehOpj1gQezNqoQINW/23jci5xQVwjS/hCMC4Q= +go.aporeto.io/wsc v1.51.1-0.20230516221449-e7ab6eb42d60/go.mod h1:0gL/S3uPkS4f3q7/lXF5Hlt804T0d9EhgOSYJkHUbVo= +go.aporeto.io/wsc v1.52.0 h1:iy2FR+P8rG7lG/c4pWXZJSDaj4jesgM4KfcbGQZB0kc= +go.aporeto.io/wsc v1.52.0/go.mod h1:0gL/S3uPkS4f3q7/lXF5Hlt804T0d9EhgOSYJkHUbVo= go.etcd.io/etcd/api/v3 v3.5.6/go.mod h1:KFtNaxGDw4Yx/BA4iPPwevUTAuqcsPxzyX8PHydchN8= go.etcd.io/etcd/client/pkg/v3 v3.5.6/go.mod h1:ggrwbk069qxpKPq8/FKkQ3Xq9y39kbFR4LnKszpRXeQ= go.etcd.io/etcd/client/v2 v2.305.6/go.mod h1:BHha8XJGe8vCIBfWBpbBLVZ4QjOIlfoouvOwydu63E0= diff --git a/server/handle_subscribe_ws.go b/server/handle_subscribe_ws.go index a0380b7..8074927 100644 --- a/server/handle_subscribe_ws.go +++ b/server/handle_subscribe_ws.go @@ -3,6 +3,7 @@ package server import ( "fmt" "net/http" + "time" "github.com/gorilla/websocket" "go.aporeto.io/wsc" @@ -26,7 +27,10 @@ func makeSubscribeWSHandler(dispatch *dispatcher) func(http.ResponseWriter, *htt return } - conn, err := wsc.Accept(r.Context(), ws, wsc.Config{}) + conn, err := wsc.Accept(r.Context(), ws, wsc.Config{ + PingPeriod: 15 * time.Minute, + PongWait: 20 * time.Minute, + }) if err != nil { http.Error( w,