Skip to content

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

Closed

Description

@spigo

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator? (not spec-specific)
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

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.

openapi-generator version

master (57164fa). Not a regression.

OpenAPI declaration file content or url

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 @MainActor PetAPI.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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions