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.
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""splinter -- prove the A2A server gives up on a client that goes quiet.
|
|
|
|
Same shape as slow_client.py, for the A2A server: it serves one connection at
|
|
a time, so a client that opens a socket and sends nothing must not hold the
|
|
next request. Before the read timeout was bounded, that client held the server
|
|
for five minutes.
|
|
|
|
argv: port, path. Exit 0 when the second client got a reply.
|
|
"""
|
|
import socket
|
|
import sys
|
|
import time
|
|
|
|
port = int(sys.argv[1])
|
|
path = sys.argv[2] if len(sys.argv) > 2 else "/a2a"
|
|
|
|
lazy = socket.create_connection(("127.0.0.1", port), timeout=10)
|
|
lazy.sendall(b"POST " + path.encode() + b" HTTP/1.1\r\nHost: x\r\nContent-Le")
|
|
# the server's read timeout is 2s here; wait past it
|
|
time.sleep(3.0)
|
|
|
|
body = (b'{"jsonrpc":"2.0","id":"1","method":"SendMessage","params":{"message":'
|
|
b'{"messageId":"m","role":"ROLE_USER","parts":[{"text":"hallo"}]}}}')
|
|
good = socket.create_connection(("127.0.0.1", port), timeout=15)
|
|
good.sendall(
|
|
b"POST " + path.encode() + b" HTTP/1.1\r\nHost: x\r\n"
|
|
b"Connection: close\r\nContent-Type: application/json\r\n"
|
|
b"Content-Length: %d\r\n\r\n" % len(body) + body)
|
|
good.settimeout(15)
|
|
try:
|
|
data = good.recv(400)
|
|
except socket.timeout:
|
|
print("second client got nothing: the server 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)
|