Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpClient abort issues in WASM when streaming #112172

Open
radderz opened this issue Feb 5, 2025 · 4 comments
Open

HttpClient abort issues in WASM when streaming #112172

radderz opened this issue Feb 5, 2025 · 4 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-System.Runtime.InteropServices.JavaScript os-browser Browser variant of arch-wasm
Milestone

Comments

@radderz
Copy link

radderz commented Feb 5, 2025

Description

When doing any form of streaming calls using HttpClient in Blazor WASM, an unhandled exception is shown (red bar by default at the bottom of screen) when there is a connection issue during streaming. I originally posted it in the aspnetcore repo but its a runtime issue.

dotnet/aspnetcore#55982

This can be triggered by a long running IAsyncEnumerable API or GRPC-Web Streaming call, I left a small repo project in the aspnetcore repo bug.

Reproduction Steps

The steps are a reasonably simple but the blazor UI needs to be connected to an api with the ability to remove connectivity (i.e. pulling out the network cable or disconnect wifi or kill the server). So the api needs to be on a different machine or be isolatable from the browser running the blazor wasm UI. Possibly devtunnels would make this easy to reproduce.

  1. Run an API with an IAsyncEnumerable endpoint that runs forever
  2. Run client connected to this endpoint on a different host
  3. Disconnect/break the network connection between the browser and the api to trigger a network error

Expected behavior

The error is bubbled up to the calling C# code that is calling the streaming.

Actual behavior

Raises an unhandled exception that the caller cannot gracefully handle and reconnect.

Regression?

No response

Known Workarounds

None

Configuration

No response

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Feb 5, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Feb 5, 2025
@radderz
Copy link
Author

radderz commented Feb 5, 2025

It looks to me that

function handle_abort_error (promise:Promise<any>) {
    promise.catch((err) => {
        if (err && err !== "AbortError" && err.name !== "AbortError" ) {
            Module.err("Unexpected error: " + err);
        }
        // otherwise, it's expected
    });
}

Should be changed to

function handle_abort_error (promise:Promise<any>) {
    promise.catch((err) => {
        if (!err) 
               return;        
        if (err === "AbortError" || err.name === "AbortError") 
                return; // normal abort
        if (err === "TypeError: network error" || (err.name === "TypeError" && err.message === "network error")) 
                return; // stream connection failure, should be handled by application

       Module.err("Unexpected error: " + err);
    });
}

Seems like a simple change.

Image

Image

@radderz
Copy link
Author

radderz commented Feb 5, 2025

https://github.com/radderz/BlazorAppJsonStreamBug

You can run the asp.net core project, which is hosting the web assembly page, once you are on the page and the timer is updating, kill the asp.net core api projects process (don't gracefully shut it down, do a kill) and you'll see the unhandled network error.

@maraf
Copy link
Member

maraf commented Feb 5, 2025

cc @pavelsavara

@maraf maraf added arch-wasm WebAssembly architecture area-System.Runtime.InteropServices.JavaScript os-browser Browser variant of arch-wasm and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Feb 5, 2025
Copy link
Contributor

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

@pavelsavara pavelsavara self-assigned this Feb 5, 2025
@pavelsavara pavelsavara added this to the 9.0.x milestone Feb 5, 2025
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Feb 5, 2025
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.Runtime.InteropServices.JavaScript os-browser Browser variant of arch-wasm
Projects
None yet
Development

No branches or pull requests

3 participants