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.
This commit is contained in:
1 parent
e7e47b7f1d
commit
0b643ca6d9
8 files changed
+165
-2
No files matched your search
+11
-1
@@ -1975,8 +1975,18 @@ sp_a2a_serve(struct sp_agent *ag, const char *ip, int port, struct sp_buf *err)
|
||||
break;
|
||||
}
|
||||
{
|
||||
struct timeval tv = { 300, 0 };
|
||||
/*
|
||||
* One connection at a time, so an unanswered read
|
||||
* holds every other client: 5 minutes was a client
|
||||
* that opened a socket and went quiet. The duration
|
||||
* covers a whole request, body included, and a test
|
||||
* can shorten it.
|
||||
*/
|
||||
const char *tmo = getenv("SPLINTER_A2A_READ_TIMEOUT");
|
||||
struct timeval tv = { 120, 0 };
|
||||
|
||||
if (tmo != NULL && atoi(tmo) > 0)
|
||||
tv.tv_sec = atoi(tmo);
|
||||
(void)setsockopt(c, SOL_SOCKET, SO_RCVTIMEO, &tv,
|
||||
sizeof(tv));
|
||||
}
|
||||
|
||||
@@ -1305,9 +1305,24 @@ sp_openai_serve(const struct sp_gateway_opts *o, struct sp_buf *err)
|
||||
(void)fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||
{
|
||||
int one_tcp = 1;
|
||||
/*
|
||||
* One connection at a time: a client that sends half
|
||||
* a header and then goes quiet used to hold the whole
|
||||
* gateway, so no other request was answered at all.
|
||||
* This bounds the read of the request; the turn that
|
||||
* follows is written to the client, not read from it.
|
||||
* SPLINTER_GATEWAY_READ_TIMEOUT lets a test prove it
|
||||
* without waiting a minute.
|
||||
*/
|
||||
const char *tmo = getenv("SPLINTER_GATEWAY_READ_TIMEOUT");
|
||||
struct timeval tv = { 60, 0 };
|
||||
|
||||
if (tmo != NULL && atoi(tmo) > 0)
|
||||
tv.tv_sec = atoi(tmo);
|
||||
(void)setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
|
||||
&one_tcp, sizeof(one_tcp));
|
||||
(void)setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv,
|
||||
sizeof(tv));
|
||||
}
|
||||
serve_one(fd, o, token);
|
||||
close(fd);
|
||||
|
||||
Reference in new issue
Block a user