Repository navigation
Conversation
Cancel outstanding proxied HTTP requests once sandbox shutdown finishes or fails. Return 502 while waiting for response headers and fail streaming bodies on their next poll. Explicit pause and WebSocket behavior are unchanged. Cover both waiting response headers and a streaming response body with regression tests. A client that stops reading can still prevent the body from being polled; bounding HTTP draining is a separate change.
|
🔍 OpenCodeReview found 2 issue(s) in this PR.
|
|
Regarding the WebSocket shutdown comment: the bridge does not use the new signal, so its sockets can remain open until the process exits. That behavior already exists before this PR. The bridge holds two sockets and a sandbox ID; it holds no guest or storage handles. After the HTTP/1 upgrade, Axum runs the bridge in a separate task, so the bridge does not keep the HTTP server waiting for shutdown. I checked this with the bridge from this PR and the pinned libraries. HTTP shutdown completed with the WebSocket still open. Dropping the Tokio runtime then dropped the bridge and both sockets. This PR leaves WebSockets unchanged. Closing them earlier can be a separate improvement; it is not needed to fix the stalled HTTP requests addressed here. |
|
@yingdi-shan @LSX-s-Software could you review this when you have a moment? It ends proxy requests that are still waiting after sandbox shutdown, while forwarding response data that is already ready to send. All checks pass, and the review comments have been addressed. |
What
End unfinished HTTP requests forwarded to sandboxes after sandbox shutdown finishes or fails. For responses already started, forward any data ready to read before ending the response.
Why
AgentENV's gateway routes a request to a runtime. The runtime's HTTP proxy forwards it to a service inside the sandbox. A command submission or file upload needs a reply from that service; the runtime cannot answer it on the guest's behalf.
Shutdown pauses the sandboxes. A request waiting for a paused guest can no longer make progress. Requests waiting for response headers eventually reach their existing timeouts, but a response that has started can wait indefinitely for another chunk.
Once sandbox shutdown returns, the process is finishing cleanup. Ending those waits tells callers that their requests were interrupted instead of leaving them waiting for a guest that will not answer.
Related issue
No separate issue. The response-header and streaming-body regressions below cover the two cancellation paths.
Companion: #510 bounds HTTP draining after cleanup, including clients that stop reading. The fixes can be reviewed and merged independently.
Scope and non-goals
This signal applies to HTTP requests forwarded into sandboxes during runtime shutdown. It does not cancel requests handled by the runtime itself, such as creating a sandbox or taking a snapshot. Those requests continue to follow the server's shutdown policy.
Explicit pause requests while the runtime remains running are unchanged. The signal does not interrupt sandbox lookup or resume, and it does not end WebSockets or their pending handshakes.
A client that stops reading can make the HTTP server stop asking the proxy for data. The proxy then cannot check cancellation. This PR alone does not bound that wait; #510 supplies a separate deadline after cleanup.
Design and behavior changes
The cleanup task runs alongside the HTTP server. It asks the orchestrator to pause and save the sandboxes. When that call returns, the task signals the proxy. It sends that signal even if sandbox shutdown returned an error, then continues releasing the remaining resources.
What the caller receives depends on how far the response has progressed:
502 Bad Gateway.For example, a complete command response already available from Hyper, the runtime's HTTP library, can reach the caller after cancellation. This does not cover bytes still waiting in the socket or being processed by Hyper; those may be lost.
flowchart TD A[Sandbox shutdown finishes or fails] --> B[Signal open proxy requests] B --> C{Still waiting for response headers?} C -->|Yes| D[Return 502] C -->|No| E[Forward available response data] E --> F{Response complete?} F -->|Yes| G[Finish normally] F -->|No| H[End the response when it needs more data]ApiImplowns the shutdown signal. Each request watches it while waiting for the guest. The response wrapper checks for available data first; it does not add a buffer or another waiting period.Before: a request to a paused guest waits for its existing timeout or for the caller to disconnect; a streaming response can wait indefinitely. After: cancellation returns 502 while waiting for headers, or ends an unfinished response after forwarding available data. A complete response already available to read can finish normally.
Compatibility and operations
tokio-utilbecomes a runtime dependency. It is already inCargo.lock; no host changes are required.Validation
Buffered-response regression passed at
63ff8ed. All 45 proxy tests passed, including delivery of a complete command acknowledgment after cancellation and interruption of a stalled response. This was a local test run; the full suites below were not repeated.Added 3 unit tests. A request waiting for response headers returns 502 after cancellation, cancellation wakes and fails a stalled response body, and a complete buffered command acknowledgment reaches the caller despite cancellation.
make fmtmake clippymake test-unitmake -C services test(required whenservices/changes)maketargetCommands and results on Linux x86_64 at
46f28d09ad99c478c228b990eb1d5157f144740c, using isolated build and test directories:The five tests initially marked ignored ran successfully in the target's capability-enabled stage.
Negative controls: disabling cancellation made the header test return 504 instead of 502 and made the body test exceed its one-second completion bound. Both failed their assertions; the outer 15-second guard did not fire. Restoring this commit passed all 44 proxy tests.
Skipped checks and reasons: The proxy regressions exercise pending headers and streaming bodies directly; full Firecracker integration tests were not run. Go service tests and API generation do not apply because their sources are unchanged. No performance benchmark was needed for these shutdown behavior tests.
Risks and reviewer notes
A 502 or broken response does not show whether the guest ran the command or wrote the file. Repeating the request can run the command twice or overwrite a file. This change does not make those retries safe.
Cancellation also happens when sandbox shutdown reports an error. Receiving the signal is not confirmation that every sandbox was saved.
Checklist