Skip to content

[NSUrlSessionHandler] Surface cancelled requests with a better exception. Fixes #25667.#25699

Open
rolfbjarne wants to merge 14 commits into
mainfrom
dev/rolf/issue-25667-stream-readasync-cancellation-test
Open

[NSUrlSessionHandler] Surface cancelled requests with a better exception. Fixes #25667.#25699
rolfbjarne wants to merge 14 commits into
mainfrom
dev/rolf/issue-25667-stream-readasync-cancellation-test

Conversation

@rolfbjarne

@rolfbjarne rolfbjarne commented Jun 16, 2026

Copy link
Copy Markdown
Member

Surface cancelled requests with an TaskCanceledException instead of a TimeoutException. This makes it easier for consumers to determine what happened.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

🤖 Pull request created by Copilot

Fixes: #25667

…ion. Fixes #25667.

Add a test: that sets up a stalling HTTP server, reads the first byte
successfully, then cancels the second ReadAsync via a caller-owned
CancellationToken.

TODO:

* Implement the fix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

Localhost server access should be reliable, so there's no need to
paper over failures with IgnoreInCI/Inconclusive.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rolfbjarne

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

rolfbjarne and others added 2 commits June 17, 2026 08:49
With Content-Length set, HttpListener may buffer the output until all
bytes are written. Switching to chunked transfer encoding ensures the
first byte reaches the client immediately, so the first ReadAsync
completes and the test can proceed to the cancellation scenario.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rolfbjarne

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne rolfbjarne marked this pull request as ready for review June 22, 2026 17:17
Copilot AI review requested due to automatic review settings June 22, 2026 17:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates NSUrlSessionHandler’s response stream read behavior so that caller-requested cancellation surfaces as an OperationCanceledException/TaskCanceledException rather than being converted into a TimeoutException (fixing #25667).

Changes:

  • Adjusts NSUrlSessionDataTaskStream.ReadAsync cancellation/timeout exception mapping.
  • Adds a regression test that reproduces stalled-response reads and asserts caller cancellation surfaces as OperationCanceledException (or subclass).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Foundation/NSUrlSessionHandler.cs Changes exception behavior when ReadAsync is canceled while polling for incoming data.
tests/monotouch-test/System.Net.Http/NSUrlSessionHandlerTest.cs Adds a TCP-based repro test ensuring caller cancellation during a stalled read yields OperationCanceledException.

Comment thread src/Foundation/NSUrlSessionHandler.cs Outdated
Comment thread tests/monotouch-test/System.Net.Http/NSUrlSessionHandlerTest.cs Outdated
Comment thread tests/monotouch-test/System.Net.Http/NSUrlSessionHandlerTest.cs Outdated
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

dalexsoto
dalexsoto previously approved these changes Jun 22, 2026
@vs-mobiletools-engineering-service2

This comment has been minimized.

rolfbjarne and others added 4 commits June 23, 2026 09:24
…nnect

- Dispose HttpResponseMessage and stream to avoid resource leaks and
  allow the TCP connection to close promptly.
- Replace Task.Delay(5 min) stall with reading until the client closes
  the connection, so the server task exits promptly after the test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #cfd4f59] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: cfd4f5954ed621ae196e5384ddf902e9bea50542 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #cfd4f59] Build passed (Build packages) ✅

Pipeline on Agent
Hash: cfd4f5954ed621ae196e5384ddf902e9bea50542 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: cfd4f5954ed621ae196e5384ddf902e9bea50542 [PR build]

@rolfbjarne rolfbjarne enabled auto-merge (squash) June 23, 2026 08:11
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #cfd4f59] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: cfd4f5954ed621ae196e5384ddf902e9bea50542 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #cfd4f59] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 207 tests passed 🎉

Tests counts

✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 19 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 20 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: cfd4f5954ed621ae196e5384ddf902e9bea50542 [PR build]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NSUrlSessionHandler stream ReadAsync reports caller cancellation as TimeoutException on iOS/macOS

4 participants