镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[wasi] Fix WasiHttpHandler request failures, disposal and header handling - #136261

Merged
lewing merged 2 commits into
dotnet:mainfrom
lewing:lewing-wasi-http-handler-fixes
Oct 30, 2026
Merged

lewing merged 2 commits into
dotnet:mainfrom
lewing:lewing-wasi-http-handler-fixes

Conversation

@lewing

@lewing lewing commented Oct 22, 2026

Copy link
Copy Markdown
Member

Fixes several WasiHttpHandler (the wasi:http handler used by HttpClientHandler on WASI) behaviors that made failures hang or surface the wrong exception.

Request content failures hang until timeout. SendContent was started fire-and-forget, so if serializing the request content threw or was canceled, nothing observed it and the request waited for a response until HttpClient.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 the WasiOutputStream.Close() override, which finished the outgoing body. After a content failure, that threw a WitException from OutgoingBody.Finish, which replaced the original exception. Completing the body is now an explicit Finish(), 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 children and killed the process. The streams now cancel their pending wait before dropping the stream.

Chunked / Content-Length. wasi:http forbids the Transfer-Encoding header, so TransferEncodingChunked = true failed header validation. It now omits the header (and Content-Length) and lets the host chunk the body, and chunked encoding without content throws InvalidOperationException like SocketsHttpHandler. For content with a known length, Content-Length is now computed and sent.

Exception types aligned with SocketsHttpHandler.

  • Null or relative request URIs now throw InvalidOperationException, and non-http(s) schemes throw NotSupportedException; both used to throw ArgumentException.
  • wasi:io stream errors while reading the response body now throw HttpIOException(HttpRequestError.ResponseEnded) instead of a raw WitException.
  • CanRead is false after the response stream is disposed.

Validation

CoreCLR WASI, Release, wasmtime 49.0.1. Each run was done against a baseline build of the same main commit without these changes.

Run Before (pass / fail / skip) After (pass / fail / skip)
System.Net.Http.Functional.Tests innerloop 768 / 0 / 23 (791 run) 768 / 0 / 23 (791 run)
OuterLoop HttpClientHandler_RemoteServerTest, SocketsHttpHandler_PostScenarioTest, SocketsHttpHandler_ResponseStreamTest 35 / 338 / 3 37 / 336 / 3
  • No test regressed from pass to fail.
  • SendAsync_SendSameRequestMultipleTimesDirectlyOnHandler_Success now passes (2 cases) because Content-Length is sent.
  • The remaining outerloop failures are pre-existing on WASI: MD5 is unavailable, TLS to the dev-cert echo server fails, and the handler has unsupported features.
  • On main, the shared HttpClientHandlerTest bodies 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.

lewing and others added 2 commits October 21, 2026 20:07
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

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@lewing lewing added arch-wasm WebAssembly architecture os-wasi Related to WASI variant of arch-wasm labels Oct 22, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

@pavelsavara
pavelsavara self-requested a review October 22, 2026 09:50
@lewing
lewing marked this pull request as ready for review October 24, 2026 02:56
@lewing
lewing requested a review from radekdoulik October 26, 2026 16:08
@lewing

lewing commented Oct 27, 2026

Copy link
Copy Markdown
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.

@lewing

lewing commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

#136684 has the test support for WasiHttpHandler

@lewing
lewing merged commit a932cb6 into dotnet:main Oct 30, 2026
103 of 106 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-System.Net.Http os-wasi Related to WASI variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants