[browser] [wasm] Remove manual ThrowIfCancellationRequested from ReadAsync response streaming#91834
Merged
pavelsavara merged 1 commit intodotnet:mainfrom Sep 11, 2023
Conversation
|
Tagging subscribers to this area: @dotnet/ncl Issue DetailsWhile working on #91699 I noticed that there was one manual call to It normally shouldn't be an issue because developers are supposed to dispose the With this PR this would also abort the fetch request: var request = new HttpRequestMessage(HttpMethod.Get, "https://someurl");
request.SetBrowserResponseStreamingEnabled(true);
var response = await new HttpClient().SendAsync(request, HttpCompletionOption.ResponseHeadersRead); // no using / dispose
var stream = await response.Content.ReadAsStreamAsync(); // no using / dispose
await stream.ReadAsync(Array.Emtpy<byte>(), new CancellationToken(true)); // now aborts fetch!
|
lewing
approved these changes
Sep 11, 2023
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
While working on #91699 I noticed that there was one manual call to
ThrowIfCancellationRequestedinReadAsyncwhen doing response streaming, which means that this cancellation token does not go through theCancelationHelperwhich means that this won't abort the actual fetch request.It normally shouldn't be an issue because developers are supposed to dispose the
HttpResponseMessage/Streamwhich both would abort the fetch request.With this PR
ReadAsyncwould also abort the fetch request:All other methods which could have called
ThrowIfCancellationRequestedalso didn't and correctly go throughCancelationHelper.runtime/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs
Line 455 in d859279
runtime/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs
Line 504 in d859279