Skip to content

fix: add volatile and test for concurrency#2389

Merged
arnaudgiuliani merged 1 commit into
InsertKoinIO:4.2.1from
inemtsev:fix/scope-closed-volatile
Apr 9, 2026
Merged

fix: add volatile and test for concurrency#2389
arnaudgiuliani merged 1 commit into
InsertKoinIO:4.2.1from
inemtsev:fix/scope-closed-volatile

Conversation

@inemtsev
Copy link
Copy Markdown
Contributor

@inemtsev inemtsev commented Mar 29, 2026

After investigating some concurrency issues we've had with version 4.1.1, I realized most of these were fixed with 4.2.0.

But, I believe this one can still cause an issue in rare cases. _closed should be volatile because checkScopeIsOpen() reads _closed outside any lock the JVM is free to let other threads see a stale cached value of false even after close() has fully returned.

It was hard to create a test, but I managed to reproduce with some AI help.

Adding volatile fixes the failing test

@inemtsev inemtsev force-pushed the fix/scope-closed-volatile branch from 89ae0da to 7ec1ec7 Compare March 29, 2026 14:51
@inemtsev inemtsev force-pushed the fix/scope-closed-volatile branch from 7ec1ec7 to 2f33846 Compare March 29, 2026 14:56
@inemtsev
Copy link
Copy Markdown
Contributor Author

@arnaudgiuliani Do you think we can include this in the next patch version?

@arnaudgiuliani arnaudgiuliani added this to the 4.2.1 milestone Apr 1, 2026
@arnaudgiuliani arnaudgiuliani changed the base branch from main to 4.2.1 April 9, 2026 15:32
@arnaudgiuliani arnaudgiuliani merged commit b055036 into InsertKoinIO:4.2.1 Apr 9, 2026
@arnaudgiuliani
Copy link
Copy Markdown
Member

will be in 4.2.1 👍

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