-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Open
Description
Description
HttpContent.LoadIntoBufferAsync now uses LimitArrayPoolWriteStream (here) where it used to use LimitMemoryStream (here) in .NET 9.
LimitArrayPoolWriteStream.WriteAsync ignores the CancellationToken and simply returns Task.CompletedTask (here) where LimitMemoryStream.WriteAsync calls the base functionality (here) which returns a cancelled task (here).
This change in behaviour means that where, in .NET 9, a TaskCanceledException would be thrown; in .NET 10 the completed task is returned successfully.
Reproduction Steps
var httpClient = new HttpClient(new SomeHandler());
var cts = new CancellationTokenSource();
cts.Cancel();
_ = await httpClient.GetAsync("https://example.com", cts.Token);
public class SomeHandler : HttpMessageHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
return Task.FromResult(new HttpResponseMessage()
{
Content = new StringContent("Hello from SomeHandler")
});
}
}Expected behavior
Behaviour in .NET 9 - TaskCanceledException is thrown.
Actual behavior
Behaviour in .NET 10 - No exception is thrown.
Regression?
This demonstrates a regression / breaking change between the versions.
Known Workarounds
No response
Configuration
- Used .NET 9 and 10
Other information
No response
Copilot and slang25