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 --- src/ot_http.c | 4 ++++ src/ot_tcp.c | 5 +++++ src/trackerlogic.h | 3 +++ 3 files changed, 12 insertions(+) (limited to 'src') diff --git a/src/ot_http.c b/src/ot_http.c index e6a8db7..29f41a3 100644 --- a/src/ot_http.c +++ b/src/ot_http.c @@ -367,6 +367,7 @@ static ssize_t http_handle_stats(const int64_t sock, struct ot_workstruct *ws, c a home of its own and only then be made reachable by a worker thread */ if (!http_adopt(sock)) HTTPERROR_500; + ws->handed_off = 1; fullscrape_deliver(sock, format); return ws->reply_size = -2; } @@ -383,6 +384,7 @@ static ssize_t http_handle_stats(const int64_t sock, struct ot_workstruct *ws, c if (!http_adopt(sock)) HTTPERROR_500; + ws->handed_off = 1; stats_deliver(sock, mode); return ws->reply_size = -2; } @@ -477,6 +479,7 @@ static ssize_t http_handle_fullscrape(const int64_t sock, struct ot_workstruct * if (!http_adopt(sock)) HTTPERROR_500; + ws->handed_off = 1; fullscrape_deliver(sock, format); return ws->reply_size = -2; } @@ -742,6 +745,7 @@ ssize_t http_handle_request(const int64_t sock, struct ot_workstruct *ws) { subroutine gets to answer: an error reply finishes with the connection on its way out, and ws outlives the connection it was serving */ ws->keep_alive = 0; + ws->handed_off = 0; #ifdef WANT_KEEPALIVE if ((write_ptr = http_header(ws->request, ws->header_size, "connection")) && (*write_ptr == 'K' || *write_ptr == 'k')) ws->keep_alive = 1; diff --git a/src/ot_tcp.c b/src/ot_tcp.c index 1351b92..f93795b 100644 --- a/src/ot_tcp.c +++ b/src/ot_tcp.c @@ -79,6 +79,11 @@ void tcp_read(const int64_t sock, struct ot_workstruct *ws) { ws->request = cookie->request.data; ws->request_size = (ssize_t)cookie->request.size; http_handle_request(sock, ws); + + /* A worker owns the connection now, and the buffer this loop reads hangs + off it, so there is nothing here left to look at */ + if (ws->handed_off) + return; #ifdef WANT_KEEPALIVE if (!ws->keep_alive) #endif diff --git a/src/trackerlogic.h b/src/trackerlogic.h index 4f970ba..d03d3b1 100644 --- a/src/trackerlogic.h +++ b/src/trackerlogic.h @@ -256,6 +256,9 @@ struct ot_workstruct { uint16_t rand48_state[3]; int keep_alive; + + /* Set when a request path gave the connection to a worker thread. */ + int handed_off; }; /* Everything a thread that serves requests needs for itself. Set up and torn -- cgit v1.3