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-runtime
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.3.0
Choose a base ref
...
head repository: apple/swift-openapi-runtime
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.3.1
Choose a head ref
  • 1 commit
  • 4 files changed
  • 2 contributors

Commits on Jan 18, 2024

  1. Bug/502 crash thread safety fix (#95)

    ### Motivation
    
    Fixes apple/swift-openapi-generator#502
    - Ensure thread safety of `HTTPBody.collect(upTo)`.
    - `makeAsyncIterator()`: Instead of crashing, return AsyncSequence which
    throws `TooManyIterationsError` thereby honoring the contract for
    `IterationBehavior.single` (HTTPBody, MultipartBody)
    
    ### Modifications
    
    - HTTPBody, MultipartBody: `makeAsyncIterator()`: removed `try!`, catch
    error and create a sequence which throws the error on iteration.
    - This removed the need for `try checkIfCanCreateIterator()` in
    `HTTPBody.collect(upTo)`.
    **Note**: This creates a small change in behavior: There may be a
    `TooManyBytesError` thrown before the check for `iterationBehavior`.
    This approach uses the simplest code, IMO. If we want to keep that
    `iterationBehavior` is checked first and only after that for the length,
    then the code needs to be more complex.
    - Removed `try checkIfCanCreateIterator()` in both classes (only used in
    `HTTPBody`).
    
    ### Result
    
    - No intentional crash in `makeAsyncIterator()` anymore.
    - Tests supplied as example in
    apple/swift-openapi-generator#502 succeed.
    
    ### Test Plan
    
    - Added check in `Test_Body.testIterationBehavior_single()` to ensure
    that using `makeAsyncIterator()` directly yields the expected error.
    - Added tests to check iteration behavior of `MultipartBody`.
    
    ---------
    
    Co-authored-by: Lars Peters <software@lpeters.net>
    LarsPetersHH and Lars Peters authored Jan 18, 2024
    Configuration menu
    Copy the full SHA
    95307ba View commit details
    Browse the repository at this point in the history
Loading