You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NET 10: Breaking change in behaviour when reading HTTP response content #121810
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
varhttpClient=newHttpClient(newSomeHandler());varcts=newCancellationTokenSource();cts.Cancel();_=awaithttpClient.GetAsync("https://example.com",cts.Token);publicclassSomeHandler:HttpMessageHandler{protectedoverrideTask<HttpResponseMessage>SendAsync(HttpRequestMessagerequest,CancellationTokencancellationToken){returnTask.FromResult(newHttpResponseMessage(){Content=newStringContent("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.
We can add back the CancellationToken checks in those write helpers, but I don't really see this as a big breaking change.
@ign3u5 did this cause you problems in practice? LimitArrayPoolWriteStream is a glorified MemoryStream, where all operations are always synchronous (no need to ever block/wait on anything).
It's normally all the operations that are actually async that you'd care about being cancellable, so you'd honor the cancellation on all the reading before you go to write into this stream.
We can add back the CancellationToken checks in those write helpers, but I don't really see this as a big breaking change.
@ign3u5 did this cause you problems in practice? LimitArrayPoolWriteStream is a glorified MemoryStream, where all operations are always synchronous (no need to ever block/wait on anything). It's normally all the operations that are actually async that you'd care about being cancellable, so you'd honor the cancellation on all the reading before you go to write into this stream.
No, nothing functional.
For context, we had a unit test that used a custom message handler to mock the response from a call, we were asserting that it threw an exception which failed when we updated to .NET 10. In actual usage though, this has no impact, as you mentioned.
I mostly raised this issue just to highlight a breaking change that I couldn't see mentioned in the list.
Activity
dotnet-policy-service commentedon Nov 19, 2025
Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.
ManickaP commentedon Nov 20, 2025
@MihaZupan looks like #109642
MihaZupan commentedon Nov 20, 2025
We can add back the
CancellationTokenchecks in those write helpers, but I don't really see this as a big breaking change.@ign3u5 did this cause you problems in practice?
LimitArrayPoolWriteStreamis a glorifiedMemoryStream, where all operations are always synchronous (no need to ever block/wait on anything).It's normally all the operations that are actually
asyncthat you'd care about being cancellable, so you'd honor the cancellation on all the reading before you go to write into this stream.ign3u5 commentedon Nov 20, 2025
No, nothing functional.
For context, we had a unit test that used a custom message handler to mock the response from a call, we were asserting that it threw an exception which failed when we updated to .NET 10. In actual usage though, this has no impact, as you mentioned.
I mostly raised this issue just to highlight a breaking change that I couldn't see mentioned in the list.