From 8f14c74be8eb8213c1ef4646646be8232bcd76d7 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 13 Mar 2016 16:41:31 -0400 Subject: [PATCH] fix issue where a seed could time-out an unchoked peer for not sending any requests, despite being busy servicing requests from the peer (and time out immediately when m_requests is drained) --- include/libtorrent/peer_connection.hpp | 4 ++++ src/peer_connection.cpp | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index 05db4ecf2..32301ddc1 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -937,6 +937,10 @@ namespace libtorrent time_point m_last_receive; time_point m_last_sent; + // the last time we filled our send buffer with payload + // this is used for timeouts + time_point m_last_sent_payload; + // the time when the first entry in the request queue was requested. Used // for request timeout. it doesn't necessarily represent the time when a // specific request was made. Since requests can be handled out-of-order, diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 53251dcf7..dba4240bc 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -137,6 +137,7 @@ namespace libtorrent , m_last_choke(min_time()) , m_last_receive(aux::time_now()) , m_last_sent(aux::time_now()) + , m_last_sent_payload(aux::time_now()) , m_requested(min_time()) , m_remote_dl_update(aux::time_now()) , m_connect(aux::time_now()) @@ -4824,10 +4825,13 @@ namespace libtorrent return; } - // disconnect peers that we unchoked, but - // they didn't send a request within 60 seconds. + // disconnect peers that we unchoked, but they didn't send a request in + // the last 60 seconds, and we haven't been working on servicing a request + // for more than 60 seconds. // but only if we're a seed - d = now - (std::max)(m_last_unchoke, m_last_incoming_request); + d = now - (std::min)((std::max)(m_last_unchoke, m_last_incoming_request) + , m_last_sent_payload); + if (may_timeout && !m_connecting && m_requests.empty() @@ -5220,6 +5224,7 @@ namespace libtorrent , boost::bind(&peer_connection::on_disk_read_complete , self(), _1, r, clock_type::now()), this); } + m_last_sent_payload = clock_type::now(); m_requests.erase(m_requests.begin() + i); if (m_requests.empty())