#!/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)