From 73aa359cb94b53e6399a000ab8bb8d85924f7d97 Mon Sep 17 00:00:00 2001 From: shengxiang Date: Tue, 7 Nov 2017 10:19:46 +0800 Subject: [PATCH] add wsReadDeadline to prevent network switch but connection still established --- main.go | 2 +- tunnelproxy.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index d84e047..98371c0 100644 --- a/main.go +++ b/main.go @@ -656,7 +656,7 @@ func main() { os.Stdin = nil log.SetOutput(f) - log.Println("Ignore SIGUP") + log.Println("Ignore SIGHUP") signal.Ignore(syscall.SIGHUP) // kill previous daemon first diff --git a/tunnelproxy.go b/tunnelproxy.go index f5ffdc1..0a64096 100644 --- a/tunnelproxy.go +++ b/tunnelproxy.go @@ -86,10 +86,16 @@ func unsafeRunTunnelProxy(serverAddr string) error { Data: devInfo, }) + // when network switch, connection still exists, but no ping comes + // server ping interval now is 10s + const wsReadWait = 60 * time.Second + ws.SetReadDeadline(time.Now().Add(wsReadWait)) ws.SetPingHandler(func(string) error { + ws.SetReadDeadline(time.Now().Add(wsReadWait)) ws.WriteMessage(websocket.PongMessage, []byte{}) return nil }) + for { _, _, err := ws.ReadMessage() if err != nil {