You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG][swift6][urlsession] Successful responses ignore apiResponseQueue and are delivered on a background thread #25204
The urlsession library delivers failures on apiResponseQueue (the main queue by default), but successful responses are delivered directly on URLSession's delegate queue: the data task's completion calls processRequestResponse(...), which calls completion(.success(...)) without going through apiResponseQueue. So, with the default configuration, an app gets errors on the main thread and results on a background thread.
Code that relies on main-queue delivery then runs off the main thread. Under Swift 6 a @MainActor closure called that way trips the runtime isolation check. This is what currently crashes the combineLibrary sample tests on Bitrise: the @MainActor test class's sink closures receive the value off main, the test process traps and is restarted for every test, and the run ends with "Executed 0 tests" / TEST EXECUTE FAILED.
Not spec-specific; reproducible with the swift6 samples' petstore spec.
Generation Details
Any swift6 config with library: urlsession (the default), e.g. bin/configs/swift6-combineLibrary.yaml or bin/configs/swift6-default.yaml.
Steps to reproduce
With the generated combineLibrary client and the default configuration:
PetAPI.addPetWithRequestBuilder(body:).execute { _ in print(Thread.isMainThread) } prints false on success
PetAPI.getPetByIdWithRequestBuilder(petId: 1).execute { ... } for a missing pet (404) prints true
A @MainActorPetAPI.getPetById(petId:).sink(...) logs data race detected: @MainActor function ... was not called on the main thread (a crash in an iOS app under Swift 6)
Expected: every result is delivered on apiResponseQueue.
Related issues/PRs
#25203 fixes the earlier sample-test failure (http redirect); with it, combineLibrary is the first sample whose tests fail.
Suggest a fix
Deliver the result of processRequestResponse on apiResponseQueue, as the failure paths already do; decoding can stay on URLSession's queue. PR follows.
Activity