From f95ac41b8f5b81f3325a67df316876766c1b29f7 Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Fri, 23 Jan 2026 14:46:40 +0100 Subject: [PATCH] fix: use smaller buffer in finish_body for faster timeout Reduce buffer size from 8192 to 1024 bytes when discarding unread body data, allowing timeouts to trigger more quickly on slow or stalled connections. --- gunicorn/http/parser.py | 4 ++-- tests/test_gthread.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gunicorn/http/parser.py b/gunicorn/http/parser.py index 5b2da115..260beafa 100644 --- a/gunicorn/http/parser.py +++ b/gunicorn/http/parser.py @@ -36,9 +36,9 @@ class Parser: """ if self.mesg: try: - data = self.mesg.body.read(8192) + data = self.mesg.body.read(1024) while data: - data = self.mesg.body.read(8192) + data = self.mesg.body.read(1024) except ssl.SSLWantReadError: # SSL socket has no more application data available pass diff --git a/tests/test_gthread.py b/tests/test_gthread.py index a085ada7..0762cc99 100644 --- a/tests/test_gthread.py +++ b/tests/test_gthread.py @@ -1443,7 +1443,7 @@ class TestFinishBodySSL: parser.finish_body() # Should not raise # Verify body.read was called - mock_body.read.assert_called_once_with(8192) + mock_body.read.assert_called_once_with(1024) def test_finish_body_reads_all_data_before_ssl_error(self): """Test that finish_body() reads all available data before SSLWantReadError.""" @@ -1513,4 +1513,4 @@ class TestFinishBodySSL: parser.finish_body() # Verify body.read was called once and returned empty - mock_body.read.assert_called_once_with(8192) + mock_body.read.assert_called_once_with(1024)