[PR #715] [CLOSED] serve: say Connection: close on every response #2782

Closed
opened 2026-11-04 02:03:05 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/715
Author: @evaanp
Created: 10/4/2026
Status: ❌ Closed

Base: main ← Head: pr/connection-close


📝 Commits (1)

  • 730b6f9 serve: say Connection: close on every response

📊 Changes

2 files changed (+40 additions, -0 deletions)

View changed files

📝 serve/server.py (+8 -0)
📝 serve/test_server.py (+32 -0)

📄 Description

What

The server speaks HTTP/1.0 and closes the connection after every response, but it never said so: no Connection
header. A client that pools connections can then hand the socket back to its pool and put its next request on it
before the server's close has reached it. That request fails with "the response ended prematurely", and the
server never reads it, so nothing shows in its log.

end_headers now adds Connection: close to every response (JSON, SSE, 204), which tells a pooling client not to
reuse the socket.

Measured

On our client, an agent app on .NET 10 (SocketsHttpHandler) with several background tasks queued behind one
another: 25 of ~1,000 requests in one night failed this way, each 1-24 ms after the previous response had
completed, and none of them reached the engine. Reproduced with a server in the same style (BaseHTTPRequestHandler,
HTTP/1.0) that delays its close by 10 ms to stand in for the network: 200 of 400 back-to-back requests failed
without the header, 0 with it.

Two tests (ConnectionClose: a non-streamed and a streamed answer carry the header); both fail without the change.
python -m unittest serve.test_server: 120 passed.

Developed with an AI coding assistant; measured on Linux, a .NET 10 client against the server on a Ryzen 7 9700X.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/715 **Author:** [@evaanp](https://github.com/evaanp) **Created:** 10/4/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/connection-close` --- ### 📝 Commits (1) - [`730b6f9`](https://github.com/Niko1221/Strata/commit/730b6f9ac5a3f806d23a0089f87a025bcb9e64f0) serve: say Connection: close on every response ### 📊 Changes **2 files changed** (+40 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+8 -0) 📝 `serve/test_server.py` (+32 -0) </details> ### 📄 Description ## What The server speaks HTTP/1.0 and closes the connection after every response, but it never said so: no `Connection` header. A client that pools connections can then hand the socket back to its pool and put its next request on it before the server's close has reached it. That request fails with "the response ended prematurely", and the server never reads it, so nothing shows in its log. `end_headers` now adds `Connection: close` to every response (JSON, SSE, 204), which tells a pooling client not to reuse the socket. ## Measured On our client, an agent app on .NET 10 (`SocketsHttpHandler`) with several background tasks queued behind one another: 25 of ~1,000 requests in one night failed this way, each 1-24 ms after the previous response had completed, and none of them reached the engine. Reproduced with a server in the same style (`BaseHTTPRequestHandler`, HTTP/1.0) that delays its close by 10 ms to stand in for the network: 200 of 400 back-to-back requests failed without the header, 0 with it. Two tests (`ConnectionClose`: a non-streamed and a streamed answer carry the header); both fail without the change. `python -m unittest serve.test_server`: 120 passed. Developed with an AI coding assistant; measured on Linux, a .NET 10 client against the server on a Ryzen 7 9700X. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:03:05 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2782
No description provided.