A shutdown no longer waits out the retries of a UDP tracker that does not answer. rtorrent stops on SIGINT in steps: it stops the downloads, writes the session, sends a "stopped" announce to every tracker in use, closes the downloads 5 s later and clears what is left of the HTTP announces 10 and 15 s after the start. Then it exits once no tracker request is in flight. A "stopped" announce over UDP starts with a connect request, and a tracker that does not answer is asked again after 15, 30 and 45 s (udp_router.cc, queue_timeout). libtorrent counts the request as disownable only after the announce packet went out, so one silent tracker holds the exit for 90 s. The upstream code says so itself: "TODO: This should e.g. timeout all udp, http, dns, etc requests" (RuntimeManager::quick_shutdown). Measured on a QTS NAS with 412 torrents, 328 of them carrying the public tracker list: 10,914 "stopped" announces, all but three answered or cleared within 16 s, and rtorrent then idle in epoll until the last retry at 90 s; 111 s in all, 28 s with this patch. With this patch the wait for trackers ends at the second clear_requests pass, 15 s after the shutdown began, as it does for HTTP. The session is written before the announces start, by the same code as before; Control::cleanup() and everything after the loop run as before, and tracker::Manager's destructor already drops requests still in flight. Verified with tools/stop-udp-test.sh (a real rtorrent against a tracker that goes silent, with and without the patch) and on QTS 6.1 (D391). --- a/src/control.cc +++ b/src/control.cc @@ -126,6 +126,13 @@ if (torrent::net_thread::http_stack()->size() != 0 || !core()->http_queue()->empty()) return false; + // handle_shutdown_clear_requests() runs at 10 s and again at 15 s after the shutdown began, and by + // then every HTTP announce is over, by force if need be. A UDP tracker that gives no answer would + // hold the exit for its whole retry ladder (15, 30 and 45 s), and the session is already on disk, + // so it gets the same time as HTTP. + if (m_clear_requests_count >= 2) + return true; + return core()->is_download_shutdown_completed(); }