[PR #4759] [Engine] serve: a stalled peer does not hold a handler or the engine's turn #5168

Open
opened 2026-11-07 16:33:12 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4759
Author: @Tsury
Created: 10/30/2026
Status: 🔄 Open

Base: main ← Head: fix-peer-stall


📝 Commits (1)

  • eafc557 [Engine] serve: a stalled peer does not hold a handler or the engine's turn

📊 Changes

2 files changed (+141 additions, -2 deletions)

View changed files

📝 serve/server.py (+9 -2)
➕ serve/test_connection_deadline.py (+132 -0)

📄 Description

Problem and result

Two peers hold server resources for good. One connects and sends nothing, which holds a handler thread. The other asks for a stream and stops reading: the write blocks while the generator is suspended inside the turn, so every other request waits behind it.

After this change, each socket operation has a deadline: STRATA_PEER_STALL_S, 120 s by default, and 0 keeps the old unbounded wait. This bounds one stalled operation, not a request. A peer that keeps sending or reading never reaches it.

Based on #2916 by @ctr-137, closed in the 0.2.0-beta tracker reset and not reopened. The test file comes from that PR, rebased on current main. If they would rather reopen theirs, I will close this one.

Approach

timeout = PEER_STALL_S on the handler class. BaseHTTPRequestHandler applies it to the connection.

Validation

Passed:

  • New tests against unchanged main (870aedd9): 4 errors. With the change: all pass.
  • python -m unittest serve.test_connection_deadline serve.test_server serve.test_structured: 372 tests pass (Linux, Python 3.14).

Not run:

  • python -m unittest discover -s serve and any GPU or model run. This change was split from a maintained v0.2.8 build that runs on an RTX 5090 Laptop; the unit tests above are the evidence for this branch.

Limits

This changes a default. A client that stops reading for more than 120 s while staying connected loses the stream; set STRATA_PEER_STALL_S=0 to keep the old behaviour.

🤖 Generated with Claude Code


🔄 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/4759 **Author:** [@Tsury](https://github.com/Tsury) **Created:** 10/30/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix-peer-stall` --- ### 📝 Commits (1) - [`eafc557`](https://github.com/Niko1221/Strata/commit/eafc55779c72a116dce88a3007830f52270ad0d1) [Engine] serve: a stalled peer does not hold a handler or the engine's turn ### 📊 Changes **2 files changed** (+141 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+9 -2) ➕ `serve/test_connection_deadline.py` (+132 -0) </details> ### 📄 Description ## Problem and result Two peers hold server resources for good. One connects and sends nothing, which holds a handler thread. The other asks for a stream and stops reading: the write blocks while the generator is suspended inside the turn, so every other request waits behind it. After this change, each socket operation has a deadline: `STRATA_PEER_STALL_S`, 120 s by default, and `0` keeps the old unbounded wait. This bounds one stalled operation, not a request. A peer that keeps sending or reading never reaches it. ## Related discussion Based on #2916 by @ctr-137, closed in the 0.2.0-beta tracker reset and not reopened. The test file comes from that PR, rebased on current `main`. If they would rather reopen theirs, I will close this one. ## Approach `timeout = PEER_STALL_S` on the handler class. `BaseHTTPRequestHandler` applies it to the connection. ## Validation **Passed:** - New tests against unchanged `main` (870aedd9): 4 errors. With the change: all pass. - `python -m unittest serve.test_connection_deadline serve.test_server serve.test_structured`: 372 tests pass (Linux, Python 3.14). **Not run:** - `python -m unittest discover -s serve` and any GPU or model run. This change was split from a maintained v0.2.8 build that runs on an RTX 5090 Laptop; the unit tests above are the evidence for this branch. ## Limits This changes a default. A client that stops reading for more than 120 s while staying connected loses the stream; set `STRATA_PEER_STALL_S=0` to keep the old behaviour. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#5168
No description provided.