Skip to content

[BUG] Swift – global mutable state causes memory corruption crashes #17377

Description

@rhys-rant

Bug Report Checklist

  • [ N/A ] Have you provided a full/minimal spec to reproduce the issue?
  • [ N/A ] Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • [ N/A ] What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I'm working on an application which has multiple API requests that fire at the same time, especially when triggered from a TaskGroup to happen simultanously. Each request attempts to do token refresh if appropriate, meaning they could – in theory – end up writing at the exact same time to the open class <GeneratedName>API class's static customHeaders property.

While I have serialised the code I've written to access the customHeaders property, I'm still getting some crashes in our Firebase from where OpenAPI Generator internals are accessing that property – presumably at the same time it's being written to.

openapi-generator version

7.1, but this has existed at least as long as openapi-generator has supported async/await.

Steps to reproduce

Use a TaskGroup that sometimes simultaneously write to the generated <GeneratedName>API.customHeaders property. Sometimes (but not always, given this is a data race) this will cause a memory corruption error and crash the application.

Suggest a fix

If it was at all possible to completely isolate these properties using an actor, I believe that would be the most ideal solution. Failing that, using some sort of lock – or at least serialising access via a queue – would probably help.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions