Skip to content

Commit 6b8eed5

Browse files
committed
fix(client): suppress write error log during reconnect
Cloudflare hard-resets WSS after 300s. The UDP→WSS goroutine from the previous connection races to write a packet to the closed socket and logs a spurious error. Suppress it when subCtx is already cancelled (i.e. the reconnect was expected, not a real write failure).
1 parent b42d2f4 commit 6b8eed5

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

client/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ func runOneTunnel(ctx context.Context, udpConn *net.UDPConn, ws *websocket.Conn)
160160
}
161161
ws.SetWriteDeadline(time.Now().Add(10 * time.Second))
162162
if err := ws.WriteMessage(websocket.BinaryMessage, buf[:n]); err != nil {
163-
log.Printf("[wss] write: %v", err)
163+
// Suppress noise when the connection was closed intentionally
164+
// (e.g. Cloudflare 300s hard-reset → reconnect in progress).
165+
if subCtx.Err() == nil {
166+
log.Printf("[wss] write: %v", err)
167+
}
164168
return
165169
}
166170
}

0 commit comments

Comments
 (0)