brontide: set read deadlines on socket during initial handshake
This commit fixes a lingering issue within lnd, which can cause a server to freeze up, and not handle any incoming connections properly, or cause clients to freeze and not return in a timely manner from a failed connection attempt. To avoid this, each time we need to read from the socket during the initial brontide handshake, we add a 15 second read deadline. If we don’t successfully read from the buffer during that time frame, then the Read method will return a timeout error. With this in place, we ensure that the main listener goroutine will never be blocked waiting on a remote party to write ActOne.
This commit is contained in:
2 files changed
+24
No files matched your search
@@ -55,6 +55,11 @@ func Dial(localPriv *btcec.PrivateKey, netAddr *lnwire.NetAddress) (*Conn, error
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// We'll ensure that we get ActTwo from the remote peer in a timely
|
||||
// manner. If they don't respond within 15 seconds, then we'll kill the
|
||||
// connection.
|
||||
conn.SetReadDeadline(time.Now().Add(time.Second * 15))
|
||||
|
||||
// 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
|
||||
// send our static public key to the remote peer with strong forward
|
||||
@@ -81,6 +86,10 @@ func Dial(localPriv *btcec.PrivateKey, netAddr *lnwire.NetAddress) (*Conn, error
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// We'll reset the deadline as it's no longer critical beyond the
|
||||
// initial handshake.
|
||||
conn.SetReadDeadline(time.Time{})
|
||||
|
||||
return b, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user