Skip to content

[swift6][urlsession] Deliver successful responses on apiResponseQueue - #25205

Merged
4brunu merged 1 commit into
OpenAPITools:masterfrom
spigo:swift6-urlsession-response-queue
Oct 9, 2026
Merged

4brunu merged 1 commit into
OpenAPITools:masterfrom
spigo:swift6-urlsession-response-queue

Conversation

@spigo

@spigo spigo commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #25204.

The urlsession request builder delivered failures on apiResponseQueue (the main queue by default), but called the completion of successful responses directly on URLSession's delegate queue. This change sends the result of processRequestResponse through apiResponseQueue as well, so every result arrives where callers expect it. Decoding still happens on URLSession's queue; only the delivery moves. The retry and failure paths already dispatched to apiResponseQueue, so nothing is dispatched twice.

This also fixes the next sample-test failure on Bitrise after #25203: the combineLibrary test class is @MainActor, so its Combine sink closures crashed under Swift 6's runtime isolation check when a successful response arrived off the main thread.

Verified with the generated combineLibrary client against https://petstore.swagger.io: before, a successful addPet and getPetById completed off the main thread and a 404 on it, and a @MainActor sink logged data race detected: @MainActor function ... was not called on the main thread. After, all three complete on the main thread and the sink runs without the warning. The default, urlsessionLibrary and combineLibrary samples build.

PR checklist


Summary by cubic

Fixes #25204 by delivering successful URLSession responses on apiResponseQueue, matching the failure path. Previously failures were dispatched to apiResponseQueue while successful responses completed directly on URLSession's delegate queue, which made @MainActor Combine sinks run off the main thread and trip Swift 6's runtime isolation check. Decoding still happens on URLSession's queue; only delivery moves. The retry and failure paths already dispatched to apiResponseQueue, so nothing is dispatched twice. This also fixes the combineLibrary sample-test failure on Bitrise.

Written for commit 28757a5. Summary will update on new commits.

View guided diff

The urlsession request builder delivered failures on apiResponseQueue
(main by default) but called the completion of successful responses
directly on URLSession's delegate queue. Callers relying on main-queue
delivery, such as @mainactor Combine sinks, then ran off the main thread;
under Swift 6 that trips the runtime isolation check and crashes the
combineLibrary sample tests. Deliver the result of processRequestResponse
on apiResponseQueue too; decoding stays on URLSession's queue. Update
swift6 samples.

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 12 files

View guided diff | Re-trigger cubic

@4brunu
4brunu merged commit 9f6536e into OpenAPITools:master Oct 9, 2026
26 of 27 checks passed
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.

[BUG][swift6][urlsession] Successful responses ignore apiResponseQueue and are delivered on a background thread

2 participants