From 399f143fdb0fd5cb95e386f7f4b65798a11aca12 Mon Sep 17 00:00:00 2001 From: maxlamagna Date: Tue, 11 Aug 2026 21:47:57 +0100 Subject: [PATCH] fix(tests): consume the request body in the proxy stub before replying ProxyHeaderForwardingTests' stub replies to a POST without reading the request body. Closing a socket that still holds unread data makes the OS send RST rather than a clean FIN, and RST tells the peer's kernel to discard what it has already buffered for that socket - including the response the client received but had not yet read. mcp_proxy then correctly surfaces the dead connection as a 502, so the test fails while the product code is behaving properly. It is load-sensitive, which is why the same commit can pass one run and fail the next. The sibling stub in this class only implements do_GET, which carries no request body and so cannot hit this. --- tests/test_identity_contract.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_identity_contract.py b/tests/test_identity_contract.py index 78f118be..5725a529 100644 --- a/tests/test_identity_contract.py +++ b/tests/test_identity_contract.py @@ -346,6 +346,11 @@ def log_message(self, format, *args): pass def do_POST(self): + # Consume the request body before replying. Closing a socket + # with unread data makes the OS send RST, which can discard the + # response already sitting in the client's receive queue - the + # source of a load-sensitive 502 failure in this test. + self.rfile.read(int(self.headers.get("Content-Length") or 0)) seen["authorization"] = self.headers.get("Authorization") seen["agent_token"] = self.headers.get("X-Agent-Token") body = b'event: message\r\ndata: {"jsonrpc":"2.0","id":1,"result":{"ok":true}}\r\n\r\n'