Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: apple/swift-openapi-urlsession
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.0.0
Choose a base ref
...
head repository: apple/swift-openapi-urlsession
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.0.1
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Jan 16, 2024

  1. Tolerate both CancellationError and URLError in CancellationTests (#45)

    ### Motivation
    
    When cancelling a Swift concurrency task during a streaming request then
    the error returned might be `URLError` with `.cancelled` code or
    `CancellationError`. The tests tried to be smart and expect just one of
    these depending on which stage of the request we were at, but there are
    still some races, and this test fails very rarely because a
    `CancellationError` was thrown instead of a `URLError`.
    
    ### Modifications
    
    This patch updates the test to tolerate both kinds of error at this
    stage of the request.
    
    ### Result
    
    The test will pass if the error is either `URLError` with `.cancelled`
    or `CancellationError`, and continue to fail if there is any other kind
    of error or no error.
    
    ### Test Plan
    
    Existing tests, which failed when run repeatedly for 1k runs, now pass
    when run for 10k runs.
    simonjbeaumont authored Jan 16, 2024
    Configuration menu
    Copy the full SHA
    3d1f6e7 View commit details
    Browse the repository at this point in the history
  2. Set OutputStream.delegate to nil in HTTPBodyOutputStreamBridge.deinit (

    …#46)
    
    ### Motivation
    
    When running the cancellation tests in a loop, very occasionally there
    would be a crash with the following backtrace:
    
    ```
    #0	0x000000018aa008d4 in objc_opt_respondsToSelector ()
    #1	0x000000018aea3410 in _outputStreamCallbackFunc ()
    #2	0x000000018aea3310 in _signalEventSync ()
    #3	0x000000018aeecdb0 in ___signalEventQueue_block_invoke ()
    #4	0x000000018abe6cb8 in _dispatch_call_block_and_release ()
    #5	0x000000018abe8910 in _dispatch_client_callout ()
    #6	0x000000018abefea4 in _dispatch_lane_serial_drain ()
    #7	0x000000018abf0a08 in _dispatch_lane_invoke ()
    #8	0x000000018abfb61c in _dispatch_root_queue_drain_deferred_wlh ()
    #9	0x000000018abfae90 in _dispatch_workloop_worker_thread ()
    #10	0x000000018ad96114 in _pthread_wqthread ()
    ```
    
    This seems to indicate that the output stream is trying to access its
    delegate. However, when running with debug logging enabled I can see
    that the delegate has already been deinitialized.
    
    This is likely a result of the delegate itself owning the stream and
    setting the stream delegate to `self`, which IIUC is an established
    pattern. This presents a race in teardown.
    
    ### Modifications
    
    This patch sets the output stream delegate to `nil` in the delegate
    `deinit`.
    
    ### Result
    
    No attempts to call the delegate will happen after it is has been
    deinitailzed.
    
    ### Test Plan
    
    With this patch, the failing test passes when run an order of magnitude
    more times than were required to reliably reproduce the crash without
    the patch.
    simonjbeaumont authored Jan 16, 2024
    Configuration menu
    Copy the full SHA
    6efbfda View commit details
    Browse the repository at this point in the history
Loading