Skip to content

Fix race condition on concurrent first invocations#144

Open
jalalawqati wants to merge 1 commit into
Kolos65:mainfrom
jalalawqati:invocations-thread-safety
Open

Fix race condition on concurrent first invocations#144
jalalawqati wants to merge 1 commit into
Kolos65:mainfrom
jalalawqati:invocations-thread-safety

Conversation

@jalalawqati
Copy link
Copy Markdown

invocations was a private lazy var. Swift lazy vars are not thread-safe, and if multiple threads access one before it's initialized, each creates its own instance and only the last one is kept. This caused verify to sometimes report 0 invocations for methods that were called, when those calls happened concurrently (e.g. via async let)

The fix is to initialize invocations eagerly in init(). Also changed returns, actions, invocations and invocationsSubject from var to let

@Kolos65
Copy link
Copy Markdown
Owner

Kolos65 commented May 11, 2026

@jalalawqati Thanks for the fix, LGTM

@jalalawqati jalalawqati force-pushed the invocations-thread-safety branch from 8849249 to 58c4dcd Compare May 19, 2026 13:24
@jalalawqati
Copy link
Copy Markdown
Author

@Kolos65 Thanks for taking a look. I made a change and force-pushed the branch. Can you re-run the checks please?

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.

2 participants