Repository navigation
[wasi] Fix WasiHttpHandler request failures, disposal and header handling - #136261
Merged
Merged
Conversation
Throw InvalidOperationException/NotSupportedException for missing, relative or unsupported request URIs, translate wasi:io stream errors on the response body into HttpIOException(ResponseEnded), and report CanRead=false after the response stream is disposed. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Observe the request-content send task while waiting for the response, so a failure in the content (or its cancellation) fails the request with the original exception instead of hanging until HttpClient.Timeout. Also: - abort, rather than finish, the outgoing body when the request wrapper is disposed before the content completes; - release pending wasi:io pollables before dropping request/response streams, avoiding the 'resource has children' trap; - translate TransferEncodingChunked into a body without Content-Length, since wasi:http forbids the Transfer-Encoding header, and send Content-Length for content of known length. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 4 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
Contributor
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
pavelsavara
self-requested a review
October 22, 2026 09:50
lewing
marked this pull request as ready for review
October 24, 2026 02:56
Member
Author
|
I have a full test standup for this that needs to stack on the socketshttphandler/websocket pr that demonstrated the need for this. |
Member
Author
|
#136684 has the test support for WasiHttpHandler |
pavelsavara
approved these changes
Oct 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes several WasiHttpHandler (the
wasi:httphandler used byHttpClientHandleron WASI) behaviors that made failures hang or surface the wrong exception.Request content failures hang until timeout.
SendContentwas started fire-and-forget, so if serializing the request content threw or was canceled, nothing observed it and the request waited for a response untilHttpClient.Timeout(100s). The handler now watches the send task while polling for the response and fails the request with the content's exception.Dispose hides the real exception.
Stream.Dispose()called theWasiOutputStream.Close()override, which finished the outgoing body. After a content failure, that threw aWitExceptionfromOutgoingBody.Finish, which replaced the original exception. Completing the body is now an explicitFinish(), and disposing an unfinished stream aborts the body.Pending-pollable disposal trap. Dropping a request or response stream while a read or write pollable (a child resource) was still registered trapped wasmtime with
resource has childrenand killed the process. The streams now cancel their pending wait before dropping the stream.Chunked / Content-Length.
wasi:httpforbids theTransfer-Encodingheader, soTransferEncodingChunked = truefailed header validation. It now omits the header (andContent-Length) and lets the host chunk the body, and chunked encoding without content throwsInvalidOperationExceptionlike SocketsHttpHandler. For content with a known length,Content-Lengthis now computed and sent.Exception types aligned with SocketsHttpHandler.
InvalidOperationException, and non-http(s) schemes throwNotSupportedException; both used to throwArgumentException.wasi:iostream errors while reading the response body now throwHttpIOException(HttpRequestError.ResponseEnded)instead of a rawWitException.CanReadisfalseafter the response stream is disposed.Validation
CoreCLR WASI, Release, wasmtime 49.0.1. Each run was done against a baseline build of the same
maincommit without these changes.System.Net.Http.Functional.TestsinnerloopHttpClientHandler_RemoteServerTest,SocketsHttpHandler_PostScenarioTest,SocketsHttpHandler_ResponseStreamTestSendAsync_SendSameRequestMultipleTimesDirectlyOnHandler_Successnow passes (2 cases) becauseContent-Lengthis sent.main, the sharedHttpClientHandlerTestbodies don't run against this handler on WASI. They're exercised by a follow-up WASI-only WasiHttpHandler test project, where the request-content-failure, cancellation and response-stream tests pass with these changes.Note
This PR description and the changes were generated with GitHub Copilot.