Skip to content

Commit 9d96f4d

Browse files
committed
disable the default tcp keepalive mechanism
1 parent 5645e64 commit 9d96f4d

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
VERSION=$(shell git describe --abbrev=0 --tags)
2-
DIRBASE=./build
3-
DIR=${DIRBASE}/${VERSION}/bin
2+
BUILD=$(shell git rev-parse HEAD)
3+
DIRBUILD=./build
4+
# DIR=${DIRBUILD}/${VERSION}/${BUILD}/bin
5+
DIR=${DIRBUILD}
46

7+
# LDFLAGS=-ldflags "-s -w ${XBUILD} -buildid=${BUILD} -X github.com/jpillora/chisel/share.BuildVersion=${VERSION}"
58
LDFLAGS=-ldflags "-s -w ${XBUILD} -buildid= -X github.com/jpillora/chisel/share.BuildVersion=${VERSION}"
69

710
GOFILES=`go list ./...`
@@ -48,6 +51,6 @@ release: lint test
4851
goreleaser release --config .github/goreleaser.yml
4952

5053
clean:
51-
rm -rf ${DIRBASE}/*
54+
rm -rf ${DIRBUILD}/*
5255

5356
.PHONY: all freebsd linux windows docker dep lint test release clean

client/client.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ func NewClient(c *Config) (*Client, error) {
7070
return nil, err
7171
}
7272
//swap to websockets scheme
73-
// if !strings.HasPrefix(c.Server, "ws") {
7473
u.Scheme = strings.Replace(u.Scheme, "http", "ws", 1)
75-
// }
7674
//apply default port
7775
if !regexp.MustCompile(`:\d+$`).MatchString(u.Host) {
7876
u.Host = u.Host + ":2871"

client/client_connect.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"io"
8+
"net"
89
"strings"
910
"time"
1011

@@ -93,6 +94,11 @@ func (c *Client) connectionOnce(ctx context.Context) (connected bool, err error)
9394
if err != nil {
9495
return false, err
9596
}
97+
// disable the default tcp keepalive mechanism.
98+
uwsConn := wsConn.UnderlyingConn()
99+
if tcpConn, ok := uwsConn.(*net.TCPConn); ok {
100+
tcpConn.SetKeepAlive(false)
101+
}
96102
conn := cnet.NewWebSocketConn(wsConn)
97103
// perform SSH handshake on net.Conn
98104
c.Debugf("Handshaking...")

server/server.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/jpillora/chisel/share/settings"
2020
"github.com/jpillora/requestlog"
2121
"golang.org/x/crypto/ssh"
22-
// websocket "github.com/lxzan/gws"
2322
)
2423

2524
// Config is the configuration for the chisel service

server/server_handler.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package chserver
22

33
import (
4+
"net"
45
"net/http"
56
"strings"
67
"sync/atomic"
@@ -56,6 +57,11 @@ func (s *Server) handleWebsocket(w http.ResponseWriter, req *http.Request) {
5657
l.Debugf("Failed to upgrade (%s)", err)
5758
return
5859
}
60+
// disable the default tcp keepalive mechanism.
61+
uwsConn := wsConn.UnderlyingConn()
62+
if tcpConn, ok := uwsConn.(*net.TCPConn); ok {
63+
tcpConn.SetKeepAlive(false)
64+
}
5965
conn := cnet.NewWebSocketConn(wsConn)
6066
// perform SSH handshake on net.Conn
6167
l.Debugf("Handshaking with %s...", req.RemoteAddr)

0 commit comments

Comments
 (0)