From c86b1c87d543b4dd50f371bdf85487a13c835c80 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Sat, 25 Apr 2020 22:49:07 +0200 Subject: [PATCH] Add timeout for initial handshake. --- client.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/client.go b/client.go index e71a660..d60ba50 100644 --- a/client.go +++ b/client.go @@ -108,11 +108,23 @@ type closeMessage struct { func startClient(conn *websocket.Conn) (err error) { var m clientMessage + + err = conn.SetReadDeadline(time.Now().Add(15 * time.Second)) + if err != nil { + conn.Close() + return + } err = conn.ReadJSON(&m) if err != nil { conn.Close() return } + err = conn.SetReadDeadline(time.Time{}) + if err != nil { + conn.Close() + return + } + if m.Type != "handshake" { conn.Close() return