Skip to content

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

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

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

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

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

🤖 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.

@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.

HttpListener buffers output even with chunked encoding, preventing the
first byte from reaching the client in time. Using a raw TcpListener
with NoDelay lets us write HTTP response bytes directly to the socket,
ensuring the first chunk is delivered immediately so the test can
proceed to the cancellation scenario.

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

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

Three changes to make the test work reliably:

1. Wait for the complete HTTP request (\r\n\r\n) before sending the
   response, to avoid confusing the HTTP framing.

2. Use Content-Length framing instead of chunked encoding, and send
   4KB of body data (NSUrlSession may buffer very small payloads
   before calling DidReceiveData).

3. Declare a Content-Length 10x larger than the data actually sent,
   so the connection stays open and ReadAsync blocks in the polling
   loop waiting for more data.

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

Copy link
Copy Markdown
Collaborator

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

Pipeline on Agent
Hash: 913e4f8291e137868e04bb0c35bd4038759a15ea [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #913e4f8] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 913e4f8291e137868e04bb0c35bd4038759a15ea [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: 913e4f8291e137868e04bb0c35bd4038759a15ea [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #913e4f8] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 913e4f8291e137868e04bb0c35bd4038759a15ea [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🔥 [CI Build #913e4f8] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 91 tests failed, 102 tests passed.

Failures

❌ monotouch tests (iOS)

20 tests failed, 0 tests passed.

Failed tests

  • monotouch-test/iOS - simulator/Debug: Failed
  • monotouch-test/iOS - simulator/Release (link sdk): Failed
  • monotouch-test/iOS - simulator/Release (link all): Failed
  • monotouch-test/iOS - simulator/Debug (LinkSdk): Failed
  • monotouch-test/iOS - simulator/Debug (static registrar): Failed
  • monotouch-test/iOS - simulator/Release (all optimizations): Failed
  • monotouch-test/iOS - simulator/Debug (ARM64): Failed
  • monotouch-test/iOS - simulator/Release (NativeAOT, ARM64): Failed
  • monotouch-test/iOS - simulator/Release (trimmable static registrar, NativeAOT, ARM64): Failed
  • monotouch-test/iOS - simulator/Debug (managed static registrar): Failed
  • monotouch-test/iOS - simulator/Release (managed static registrar, all optimizations): Failed
  • monotouch-test/iOS - simulator/Release (NativeAOT, x64): Failed
  • monotouch-test/iOS - simulator/Release (trimmable static registrar, NativeAOT, x64): Failed
  • monotouch-test/iOS - simulator/Debug (interpreter): Failed
  • monotouch-test/iOS - simulator/Release (interpreter): Failed
  • monotouch-test/iOS - simulator/Release (compat inline Class.GetHandle): Failed
  • monotouch-test/iOS - simulator/Release (strict inline Class.GetHandle): Failed
  • monotouch-test/iOS - simulator/Release (compat inline dlfcn): Failed
  • monotouch-test/iOS - simulator/Release (strict inline dlfcn, link sdk): Failed
  • monotouch-test/iOS - simulator/Release (NativeAOT, .NET 11 defaults): Failed

Html Report (VSDrops) Download

❌ monotouch tests (MacCatalyst)

23 tests failed, 0 tests passed.

Failed tests

  • monotouch-test/Mac Catalyst/Debug: Failed (Test run failed.
    Tests run: 3771 Passed: 3613 Inconclusive: 10 Failed: 1 Ignored: 157)
  • monotouch-test/Mac Catalyst/Release (link sdk): Failed (Test run failed.
    Tests run: 3768 Passed: 3606 Inconclusive: 10 Failed: 1 Ignored: 161)
  • monotouch-test/Mac Catalyst/Release (link all): Failed (Test run failed.
    Tests run: 3768 Passed: 3605 Inconclusive: 10 Failed: 1 Ignored: 162)
  • monotouch-test/Mac Catalyst/Debug (ARM64): Failed (Test run failed.
    Tests run: 3771 Passed: 3613 Inconclusive: 10 Failed: 1 Ignored: 157)
  • monotouch-test/Mac Catalyst/Debug (managed static registrar): Failed (Test run failed.
    Tests run: 3768 Passed: 3611 Inconclusive: 10 Failed: 1 Ignored: 156)
  • monotouch-test/Mac Catalyst/Debug (static registrar): Failed (Test run failed.
    Tests run: 3768 Passed: 3612 Inconclusive: 10 Failed: 1 Ignored: 155)
  • monotouch-test/Mac Catalyst/Debug (static registrar, ARM64): Failed (Test run failed.
    Tests run: 3768 Passed: 3612 Inconclusive: 10 Failed: 1 Ignored: 155)
  • monotouch-test/Mac Catalyst/Release (managed static registrar): Failed (Test run failed.
    Tests run: 3768 Passed: 3606 Inconclusive: 10 Failed: 1 Ignored: 161)
  • monotouch-test/Mac Catalyst/Release (managed static registrar, all optimizations): Failed (Test run failed.
    Tests run: 3768 Passed: 3600 Inconclusive: 10 Failed: 1 Ignored: 167)
  • monotouch-test/Mac Catalyst/Release (NativeAOT): Failed (Test run failed.
    Tests run: 3768 Passed: 3595 Inconclusive: 10 Failed: 1 Ignored: 172)
  • monotouch-test/Mac Catalyst/Release (NativeAOT, ARM64): Failed (Test run failed.
    Tests run: 3768 Passed: 3595 Inconclusive: 10 Failed: 1 Ignored: 172)
  • monotouch-test/Mac Catalyst/Release (NativeAOT, x64): Failed (Test run failed.
    Tests run: 3768 Passed: 3593 Inconclusive: 10 Failed: 1 Ignored: 174)
  • monotouch-test/Mac Catalyst/Release (NativeAOT, .NET 11 defaults): Failed (Test run failed.
    Tests run: 3768 Passed: 3595 Inconclusive: 10 Failed: 1 Ignored: 172)
  • monotouch-test/Mac Catalyst/Release (trimmable static registrar, NativeAOT): Failed (Test run failed.
    Tests run: 3768 Passed: 3596 Inconclusive: 10 Failed: 1 Ignored: 171)
  • monotouch-test/Mac Catalyst/Release (trimmable static registrar, NativeAOT, ARM64): Failed (Test run failed.
    Tests run: 3768 Passed: 3596 Inconclusive: 10 Failed: 1 Ignored: 171)
  • monotouch-test/Mac Catalyst/Release (trimmable static registrar, NativeAOT, x64): Failed (Test run failed.
    Tests run: 3768 Passed: 3593 Inconclusive: 10 Failed: 1 Ignored: 174)
  • monotouch-test/Mac Catalyst/Release (static registrar): Failed (Test run failed.
    Tests run: 3768 Passed: 3606 Inconclusive: 10 Failed: 1 Ignored: 161)
  • monotouch-test/Mac Catalyst/Release (static registrar, all optimizations): Failed (Test run failed.
    Tests run: 3768 Passed: 3599 Inconclusive: 10 Failed: 1 Ignored: 168)
  • monotouch-test/Mac Catalyst/Release (ARM64, LLVM): Failed (Test run failed.
    Tests run: 3768 Passed: 3606 Inconclusive: 10 Failed: 1 Ignored: 161)
  • monotouch-test/Mac Catalyst/Debug (interpreter): Failed (Test run failed.
    Tests run: 3771 Passed: 3610 Inconclusive: 10 Failed: 1 Ignored: 160)
  • monotouch-test/Mac Catalyst/Release (interpreter): Failed (Test run failed.
    Tests run: 3768 Passed: 3604 Inconclusive: 10 Failed: 1 Ignored: 163)
  • monotouch-test/Mac Catalyst/Release (compat inline dlfcn): Failed (Test run failed.
    Tests run: 3768 Passed: 3605 Inconclusive: 10 Failed: 1 Ignored: 162)
  • monotouch-test/Mac Catalyst/Release (strict inline dlfcn, link sdk): Failed (Test run failed.
    Tests run: 3768 Passed: 3606 Inconclusive: 10 Failed: 1 Ignored: 161)

Html Report (VSDrops) Download

❌ monotouch tests (macOS)

23 tests failed, 0 tests passed.

Failed tests

  • monotouch-test/macOS/Debug: Failed (Test run failed.
    Tests run: 3721 Passed: 3615 Inconclusive: 4 Failed: 1 Ignored: 105)
  • monotouch-test/macOS/Release (link sdk): Failed (Test run failed.
    Tests run: 3718 Passed: 3610 Inconclusive: 4 Failed: 1 Ignored: 107)
  • monotouch-test/macOS/Release (link all): Failed (Test run failed.
    Tests run: 3718 Passed: 3609 Inconclusive: 4 Failed: 1 Ignored: 108)
  • monotouch-test/macOS/Debug (ARM64): Failed (Test run failed.
    Tests run: 3721 Passed: 3615 Inconclusive: 4 Failed: 1 Ignored: 105)
  • monotouch-test/macOS/Debug (managed static registrar): Failed (Test run failed.
    Tests run: 3718 Passed: 3613 Inconclusive: 4 Failed: 1 Ignored: 104)
  • monotouch-test/macOS/Debug (trimmable static registrar): Failed (Test run failed.
    Tests run: 3718 Passed: 3612 Inconclusive: 4 Failed: 1 Ignored: 105)
  • monotouch-test/macOS/Debug (static registrar): Failed (Test run failed.
    Tests run: 3718 Passed: 3612 Inconclusive: 4 Failed: 1 Ignored: 105)
  • monotouch-test/macOS/Debug (static registrar, ARM64): Failed (Test run failed.
    Tests run: 3718 Passed: 3613 Inconclusive: 4 Failed: 1 Ignored: 104)
  • monotouch-test/macOS/Release (managed static registrar): Failed (Test run failed.
    Tests run: 3718 Passed: 3611 Inconclusive: 4 Failed: 1 Ignored: 106)
  • monotouch-test/macOS/Release (trimmable static registrar): Failed (Test run failed.
    Tests run: 3718 Passed: 3611 Inconclusive: 4 Failed: 1 Ignored: 106)
  • monotouch-test/macOS/Release (managed static registrar, all optimizations): Failed (Test run failed.
    Tests run: 3718 Passed: 3613 Inconclusive: 4 Failed: 1 Ignored: 104)
  • monotouch-test/macOS/Release (trimmable static registrar, all optimizations): Failed (Test run failed.
    Tests run: 3718 Passed: 3614 Inconclusive: 4 Failed: 1 Ignored: 103)
  • monotouch-test/macOS/Release (NativeAOT): Failed (Test run failed.
    Tests run: 3717 Passed: 3601 Inconclusive: 4 Failed: 1 Ignored: 115)
  • monotouch-test/macOS/Release (NativeAOT, ARM64): Failed (Test run failed.
    Tests run: 3717 Passed: 3601 Inconclusive: 4 Failed: 1 Ignored: 115)
  • monotouch-test/macOS/Release (NativeAOT, x64): Failed (Test run failed.
    Tests run: 3717 Passed: 3582 Inconclusive: 4 Failed: 1 Ignored: 134)
  • monotouch-test/macOS/Release (NativeAOT, .NET 11 defaults): Failed (Test run failed.
    Tests run: 3717 Passed: 3601 Inconclusive: 4 Failed: 1 Ignored: 115)
  • monotouch-test/macOS/Release (trimmable static registrar, NativeAOT): Failed (Test run failed.
    Tests run: 3717 Passed: 3601 Inconclusive: 4 Failed: 1 Ignored: 115)
  • monotouch-test/macOS/Release (trimmable static registrar, NativeAOT, ARM64): Failed (Test run failed.
    Tests run: 3717 Passed: 3601 Inconclusive: 4 Failed: 1 Ignored: 115)
  • monotouch-test/macOS/Release (trimmable static registrar, NativeAOT, x64): Failed (Test run failed.
    Tests run: 3717 Passed: 3583 Inconclusive: 4 Failed: 1 Ignored: 133)
  • monotouch-test/macOS/Release (static registrar): Failed (Test run failed.
    Tests run: 3718 Passed: 3610 Inconclusive: 4 Failed: 1 Ignored: 107)
  • monotouch-test/macOS/Release (static registrar, all optimizations): Failed (Test run failed.
    Tests run: 3718 Passed: 3613 Inconclusive: 4 Failed: 1 Ignored: 104)
  • monotouch-test/macOS/Release (compat inline dlfcn): Failed (Test run failed.
    Tests run: 3718 Passed: 3611 Inconclusive: 4 Failed: 1 Ignored: 106)
  • monotouch-test/macOS/Release (strict inline dlfcn, link sdk): Failed (Test run failed.
    Tests run: 3718 Passed: 3610 Inconclusive: 4 Failed: 1 Ignored: 107)

Html Report (VSDrops) Download

❌ monotouch tests (tvOS)

20 tests failed, 0 tests passed.

Failed tests

  • monotouch-test/tvOS - simulator/Debug: Failed
  • monotouch-test/tvOS - simulator/Release (link sdk): Failed
  • monotouch-test/tvOS - simulator/Release (link all): Failed
  • monotouch-test/tvOS - simulator/Debug (LinkSdk): BuildFailure
  • monotouch-test/tvOS - simulator/Debug (static registrar): Failed
  • monotouch-test/tvOS - simulator/Release (all optimizations): Failed
  • monotouch-test/tvOS - simulator/Debug (ARM64): Failed
  • monotouch-test/tvOS - simulator/Release (NativeAOT, ARM64): Failed
  • monotouch-test/tvOS - simulator/Release (trimmable static registrar, NativeAOT, ARM64): Failed
  • monotouch-test/tvOS - simulator/Debug (managed static registrar): Failed
  • monotouch-test/tvOS - simulator/Release (managed static registrar, all optimizations): Failed
  • monotouch-test/tvOS - simulator/Release (NativeAOT, x64): Failed
  • monotouch-test/tvOS - simulator/Release (trimmable static registrar, NativeAOT, x64): Failed
  • monotouch-test/tvOS - simulator/Debug (interpreter): Failed
  • monotouch-test/tvOS - simulator/Release (interpreter): Failed
  • monotouch-test/tvOS - simulator/Release (compat inline Class.GetHandle): Failed
  • monotouch-test/tvOS - simulator/Release (strict inline Class.GetHandle): Failed
  • monotouch-test/tvOS - simulator/Release (compat inline dlfcn): Failed
  • monotouch-test/tvOS - simulator/Release (strict inline dlfcn, link sdk): Failed
  • monotouch-test/tvOS - simulator/Release (NativeAOT, .NET 11 defaults): Failed

Html Report (VSDrops) Download

❌ Tests on macOS Monterey (12) tests

1 tests failed, 4 tests passed.

Failed tests

  • monotouch-test: Failed (exit code 2)
    • StreamReadAsyncCallerCancellationThrowsOperationCanceledException : Expected OperationCanceledException but got System.TimeoutException
    • StreamReadAsyncCallerCancellationThrowsOperationCanceledException : Expected OperationCanceledException but got System.TimeoutException
    • StreamReadAsyncCallerCancellationThrowsOperationCanceledException : Expected OperationCanceledException but got System.TimeoutException
    • ... and 1 more failures

Html Report (VSDrops) Download

❌ Tests on macOS Ventura (13) tests

1 tests failed, 4 tests passed.

Failed tests

  • monotouch-test: Failed (exit code 2)
    • StreamReadAsyncCallerCancellationThrowsOperationCanceledException : Expected OperationCanceledException but got System.TimeoutException
    • StreamReadAsyncCallerCancellationThrowsOperationCanceledException : Expected OperationCanceledException but got System.TimeoutException
    • StreamReadAsyncCallerCancellationThrowsOperationCanceledException : Expected OperationCanceledException but got System.TimeoutException
    • ... and 1 more failures

Html Report (VSDrops) Download

❌ Tests on macOS Sonoma (14) tests

1 tests failed, 4 tests passed.

Failed tests

  • monotouch-test: Failed (exit code 2)
    • StreamReadAsyncCallerCancellationThrowsOperationCanceledException : Expected OperationCanceledException but got System.TimeoutException
    • StreamReadAsyncCallerCancellationThrowsOperationCanceledException : Expected OperationCanceledException but got System.TimeoutException

Html Report (VSDrops) Download

❌ Tests on macOS Sequoia (15) tests

1 tests failed, 4 tests passed.

Failed tests

  • monotouch-test: Failed (exit code 2)
    • StreamReadAsyncCallerCancellationThrowsOperationCanceledException : Expected OperationCanceledException but got System.TimeoutException
    • StreamReadAsyncCallerCancellationThrowsOperationCanceledException : Expected OperationCanceledException but got System.TimeoutException
    • StreamReadAsyncCallerCancellationThrowsOperationCanceledException : Expected OperationCanceledException but got System.TimeoutException
    • ... and 1 more failures

Html Report (VSDrops) Download

❌ Tests on macOS Tahoe (26) tests

1 tests failed, 4 tests passed.

Failed tests

  • monotouch-test: Failed (exit code 2)
    • StreamReadAsyncCallerCancellationThrowsOperationCanceledException : Expected OperationCanceledException but got System.TimeoutException
    • StreamReadAsyncCallerCancellationThrowsOperationCanceledException : Expected OperationCanceledException but got System.TimeoutException
    • StreamReadAsyncCallerCancellationThrowsOperationCanceledException : Expected OperationCanceledException but got System.TimeoutException
    • ... and 1 more failures

Html Report (VSDrops) Download

Successes

✅ 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 6 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 11 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

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: 913e4f8291e137868e04bb0c35bd4038759a15ea [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

2 participants