Skip to content

fix: sync upstream bug fixes from swift-openapi-urlsession PRs #94 and #95 - #11

Merged
grdsdev merged 2 commits into
mainfrom
sync/upstream-urlsession-pr94-pr95
Jul 1, 2026
Merged

fix: sync upstream bug fixes from swift-openapi-urlsession PRs #94 and #95#11
grdsdev merged 2 commits into
mainfrom
sync/upstream-urlsession-pr94-pr95

Conversation

@grdsdev

@grdsdev grdsdev commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • HTTPBodyOutputStreamBridge: Added missing cancel(error:) method; fixed state machine so .closed is handled gracefully in errorOccurred, wroteFinalChunk, and endEncountered instead of calling preconditionFailure
  • BidirectionalStreamingURLSessionDelegate: Propagate URLSession task errors to the stream bridge in didCompleteWithError via requestStream?.cancel(error:)
  • HTTPBody: Replace NSLock with the internal pthread-based Lock (removing ObjC dependency for locking)
  • Scripts/check-upstream.sh: New script to compare upstream files against local copies, making future syncs easy to spot

Upstream references

Test plan

  • swift build passes
  • All unit tests pass (HTTPBodyTests, ClientTests, MiddlewareTests, MultipartFormDataTests, LoggingMiddlewareTests, ErrorTests, HTTPBodyProgressTests)
  • Integration tests pass when httpbin is running locally

grdsdev added 2 commits July 1, 2026 14:48
…d #95

- Add `cancel(error:)` to `HTTPBodyOutputStreamBridge` so URLSession
  task errors can be propagated to the stream bridge (PR #94)
- Fix `errorOccurred` state machine: `.initial` and `.waitingForBytes`
  now both close the stream; `.closed` is handled gracefully (PR #95)
- Fix `wroteFinalChunk`/`endEncountered`: `.closed` state logs and
  returns instead of calling `preconditionFailure` (PR #95)
- Propagate URLSession errors to the stream bridge in
  `BidirectionalStreamingURLSessionDelegate.didCompleteWithError` (PR #94)
- Replace `NSLock` in `HTTPBody` with the internal pthread-based `Lock`
- Add `Scripts/check-upstream.sh` to simplify future upstream syncs
…eterministic wait

The `log()` handler fires `Task { await collector.append(entry) }`, so
entries arrive asynchronously. Using a fixed 100ms sleep was racy —
in `loggingMiddlewareLogsDifferentMethods` the response Task could arrive
before the request Task, causing an order-sensitive `entries[0]` check
to fail.

- Add `waitForEntries(count:)` to `LogCollector` that polls via
  `Task.yield()` until the expected number of entries arrive
- Replace all `Task.sleep(for: .milliseconds(100))` calls with it
- Find the request log by content ("⬆️") rather than assuming index 0
- Use `waitForEntries(count: 1)` in the error test (only request is logged)
@grdsdev
grdsdev merged commit 76ded00 into main Jul 1, 2026
5 checks passed
@grdsdev
grdsdev deleted the sync/upstream-urlsession-pr94-pr95 branch July 1, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant