Files
splinter/tests/slow_client.py
T
lotherk 0b643ca6d9 servers: a silent client no longer holds the gateway or A2A server
Both HTTP servers answer one connection at a time. A client that sent half a
header and then went quiet held the whole gateway: a second client's complete
request was never answered (measured: recv timed out after 10s, with the lazy
socket open). The A2A server had the same shape with a five minute read
timeout, so one idle socket blocked every other request for five minutes.

Both now bound the read (gateway 60s, A2A 120s) and take the value from
SPLINTER_GATEWAY_READ_TIMEOUT / SPLINTER_A2A_READ_TIMEOUT so a test does not
wait a minute.

Tests: tests/slow_client.py and tests/slow_a2a_client.py open a socket, send
half a request, wait past the timeout, then send a complete one and require a
200. Without the fix both print "the server is still held" and the suite is
red; with it, test_gateway_openai: ok and test_a2a_server: ok. Full suite:
all tests passed. check_asan: all 45 test binaries clean.
2026-11-23 01:11:56 +00:00

43 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""splinter -- prove the gateway gives up on a client that goes quiet.
The accept loop serves one connection at a time. Without a read timeout a
client that sends half a header and then nothing held the whole gateway: the
second connection below was accepted by the kernel and never answered.
argv: port. Exit 0 when the second client got a reply.
"""
import socket
import sys
import time
port = int(sys.argv[1])
lazy = socket.create_connection(("127.0.0.1", port), timeout=10)
lazy.sendall(b"POST /v1/chat/completions HTTP/1.1\r\nHost: x\r\nContent-Le")
# the server's read timeout is 2s here; wait past it so the lazy client is
# dropped before the second one is queued
time.sleep(3.0)
good = socket.create_connection(("127.0.0.1", port), timeout=10)
body = b'{"model":"x","messages":[{"role":"user","content":"hi"}]}'
good.sendall(
b"POST /v1/chat/completions HTTP/1.1\r\nHost: x\r\nConnection: close\r\n"
b"Content-Type: application/json\r\nContent-Length: %d\r\n\r\n" % len(body)
+ body)
good.settimeout(10)
try:
data = good.recv(400)
except socket.timeout:
print("second client got nothing: the gateway is still held")
sys.exit(1)
finally:
lazy.close()
good.close()
if data.startswith(b"HTTP/1.1 200"):
print("second client answered")
sys.exit(0)
print("second client got %r" % data[:80])
sys.exit(1)