Skip to content

NET 10: Breaking change in behaviour when reading HTTP response content #121810

Closed

Description

@ign3u5

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

Activity

  1. added
    untriaged
    on Nov 19, 2025
  2. dotnet-policy-service commented on Nov 19, 2025

    @dotnet-policy-service
    Contributor

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

  3. ManickaP commented on Nov 20, 2025

    @ManickaP
    Member

    @MihaZupan looks like #109642

  4. MihaZupan commented on Nov 20, 2025

    @MihaZupan
    Member

    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.

  5. ign3u5 commented on Nov 20, 2025

    @ign3u5
    Author

    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.

  6. added this to the 11.0.0 milestone on Nov 20, 2025
  7. removed
    untriaged
    on Nov 20, 2025
  8. locked and limited conversation to collaborators on Dec 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions