From 8bae93ce181086769175e5c3fb0f0ef66fb9ca89 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Fri, 6 Nov 2026 03:01:46 +0100 Subject: Stop reading a connection a worker has taken over --- tests/integration/test_keepalive.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/integration/test_keepalive.py') diff --git a/tests/integration/test_keepalive.py b/tests/integration/test_keepalive.py index 01f02a5..2c724fc 100644 --- a/tests/integration/test_keepalive.py +++ b/tests/integration/test_keepalive.py @@ -7,6 +7,7 @@ the request has moved on, so whether to keep the connection has to be remembered on the connection itself. """ +import time import unittest import urllib.parse @@ -106,6 +107,24 @@ class KeepAlive(TrackerTestCase): finally: c.close() + def test_a_split_request_answered_by_a_worker_does_not_spin(self): + """A reply that a worker produces does not go through the send path, + so the request stays in the buffer the read loop is reading. The loop + used to find the same request again on every pass, queue a task for + it, and never hand the thread back to the event loop.""" + for path in ("/stats", "/scrape"): + c = self.tracker.connect() + try: + c.sock.sendall(("GET %s HTTP/1.1\r\nConnection: keep-alive\r\n" % path).encode()) + time.sleep(0.2) + c.sock.sendall(b"\r\n") + self.assertIn(b"200", c.reply()[0], "%s was not answered" % path) + finally: + c.close() + + answer = self.tracker.announce(self.hash_for("after-" + path), port=6881, left=0) + self.assertNotIn(b"failure reason", answer, "the tracker stopped serving after %s" % path) + if __name__ == "__main__": unittest.main() -- cgit v1.3