From 7ad6e235ada260c3c400bae886f5984994d55266 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sat, 18 Jan 2014 01:39:31 -0600 Subject: [PATCH] Reduce the initial idle timeout to 30 seconds. This commit reduces the initial idle timeout before version negotiation has happened on a new peer to 30 seconds. Previously it could take 5 minutes due to the general idle timeout. --- peer.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/peer.go b/peer.go index ad33404e..65c73dad 100644 --- a/peer.go +++ b/peer.go @@ -33,6 +33,11 @@ const ( // inventory cache. maxKnownInventory = 20000 + // negotiateTimeoutSeconds is the number of seconds of inactivity before + // we timeout a peer that hasn't completed the initial version + // negotiation. + negotiateTimeoutSeconds = 30 + // idleTimeoutMinutes is the number of minutes of inactivity before // we time out a peer. idleTimeoutMinutes = 5 @@ -1019,7 +1024,10 @@ func (p *peer) isAllowedByRegression(err error) bool { // inHandler handles all incoming messages for the peer. It must be run as a // goroutine. func (p *peer) inHandler() { - idleTimer := time.AfterFunc(idleTimeoutMinutes*time.Minute, func() { + // Peers must complete the initial version negotiation within a shorter + // timeframe than a general idle timeout. The timer is then reset below + // to idleTimeoutMinutes for all future messages. + idleTimer := time.AfterFunc(negotiateTimeoutSeconds*time.Second, func() { // XXX technically very very very slightly racy, doesn't really // matter. if p.versionKnown {