Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 of 3 tasks
rhys-rant opened this issue Dec 12, 2023 · 0 comments · May be fixed by #20082
Open
2 of 3 tasks

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

rhys-rant opened this issue Dec 12, 2023 · 0 comments · May be fixed by #20082

Comments

@rhys-rant
Copy link

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.

@rhys-rant rhys-rant changed the title [BUG] Swift – global mutable state can and does cause crashes [BUG] Swift – global mutable state causes memory corruption crashes Dec 12, 2023
@kalinjul kalinjul linked a pull request Nov 12, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant