From 03d044b88dd1377281caa44c0133d9f22579ba90 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 28 Nov 2026 22:16:45 +0100 Subject: Add a generation to a task on the workqueue to prevent its result being sent to the next client reusing the fd --- src/ot_tcp.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/ot_tcp.c') diff --git a/src/ot_tcp.c b/src/ot_tcp.c index 5d7b78f..67a0ebc 100644 --- a/src/ot_tcp.c +++ b/src/ot_tcp.c @@ -44,9 +44,19 @@ static ssize_t header_complete(char *request, ssize_t byte_count) { void tcp_read(const int64_t sock, struct ot_workstruct *ws) { struct http_data *cookie = fdstate_cookie(sock); - ssize_t byte_count = read((int)sock, ws->inbuf, G_INBUF_SIZE); + ssize_t byte_count; uint32_t generation; + /* We're not supposed to read from a socket that waits for + our answer. Prevent its reply from being sent to the next + generation on that fd. */ + if (cookie->flag & (STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER)) { + http_close(sock); + return; + } + + byte_count = read((int)sock, ws->inbuf, G_INBUF_SIZE); + if (byte_count == 0 || (byte_count == -1 && errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)) { http_close(sock); return; -- cgit v1.3