From 41940c6c9eaf512558a35a695e6a05367804273c Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Fri, 15 Feb 2019 18:13:52 -0800 Subject: [PATCH] brontide/conn: handle read timeout errors --- brontide/conn.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/brontide/conn.go b/brontide/conn.go index e5bfecc11..05f17be3a 100644 --- a/brontide/conn.go +++ b/brontide/conn.go @@ -61,7 +61,11 @@ func Dial(localPriv *btcec.PrivateKey, netAddr *lnwire.NetAddress, // We'll ensure that we get ActTwo from the remote peer in a timely // manner. If they don't respond within 1s, then we'll kill the // connection. - conn.SetReadDeadline(time.Now().Add(handshakeReadTimeout)) + err = conn.SetReadDeadline(time.Now().Add(handshakeReadTimeout)) + if err != nil { + b.conn.Close() + return nil, err + } // If the first act was successful (we know that address is actually // remotePub), then read the second act after which we'll be able to @@ -91,7 +95,11 @@ func Dial(localPriv *btcec.PrivateKey, netAddr *lnwire.NetAddress, // We'll reset the deadline as it's no longer critical beyond the // initial handshake. - conn.SetReadDeadline(time.Time{}) + err = conn.SetReadDeadline(time.Time{}) + if err != nil { + b.conn.Close() + return nil, err + } return b, nil }