Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
add wsReadDeadline to prevent network switch but connection still est…
Browse files Browse the repository at this point in the history
…ablished
  • Loading branch information
codeskyblue committed Nov 7, 2017
1 parent e93e51b commit 73aa359
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tunnelproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 73aa359

Please sign in to comment.