Skip to content

Fix gateway recovery after high request load - #4351

Merged
peterschmidt85 merged 3 commits into
masterfrom
issue_4338_gateway_nofile_limit
Oct 8, 2026
Merged

peterschmidt85 merged 3 commits into
masterfrom
issue_4338_gateway_nofile_limit

Conversation

@peterschmidt85

@peterschmidt85 peterschmidt85 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4338.

High request load can leave services returning HTTP 500 even after the load stops.

  • Set LimitNOFILE=65535 for the gateway Python service; nginx's limit does not apply to it.
  • Use httpx2 for authorization requests to dstack-server. Its pool releases connection slots abandoned by cancelled or timed-out requests and avoids scanning every connection for each waiting request.

The migration is limited to gateway authorization; other dstack HTTP clients continue using httpx.

Deploying the fixed server release automatically updates and restarts existing gateways under default settings, including applying the new file-descriptor limit.

Follow-up: stress-test gateway capacity and recovery under overload. Document supported request rates and concurrency, latency/error targets, and which scaling options help.

@peterschmidt85
peterschmidt85 marked this pull request as draft October 7, 2026 12:36
@peterschmidt85
peterschmidt85 marked this pull request as ready for review October 7, 2026 13:43
@peterschmidt85
peterschmidt85 requested a review from jvstme October 7, 2026 13:50
except BaseException:
# HTTPcore removes the failed/cancelled request, but can leave its newly
# assigned connection behind before it starts. That slot is never reused.
# Remove this orphan cleanup once https://github.com/encode/httpcore/pull/1099 ships.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the discussion in this PR, it may be a long time until the fix lands in httpcore and httpx, but the bug is already fixed in httpx2.

Should we consider migrating to httpx2? It's a drop-in replacement, so migrating might be easier than pinning, patching, and redistributing httpcore with its license, and we'll also benefit from other fixes and improvements.

@peterschmidt85
peterschmidt85 merged commit 009e291 into master Oct 8, 2026
50 of 51 checks passed
@peterschmidt85
peterschmidt85 deleted the issue_4338_gateway_nofile_limit branch October 8, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Gateway returns persistent HTTP 500 after high request load

2 participants