From 1b6b481fccee348075dc40b8e5a64f865c941840 Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Thu, 6 Aug 2015 12:07:34 +0100 Subject: [PATCH] Add timeout for peek (fixes #1035) --- cmd/syncthing/tls.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/syncthing/tls.go b/cmd/syncthing/tls.go index 6faafbe5e..d8b8be05f 100644 --- a/cmd/syncthing/tls.go +++ b/cmd/syncthing/tls.go @@ -102,7 +102,9 @@ func (l *DowngradingListener) Accept() (net.Conn, error) { } br := bufio.NewReader(conn) + conn.SetReadDeadline(time.Now().Add(1 * time.Second)) bs, err := br.Peek(1) + conn.SetReadDeadline(time.Time{}) if err != nil { // We hit a read error here, but the Accept() call succeeded so we must not return an error. // We return the connection as is and let whoever tries to use it deal with the error.