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

Potential race condition - JdbcTaskRepository#memoize #510

Open
NicklasWallgren opened this issue Jul 3, 2024 · 0 comments
Open

Potential race condition - JdbcTaskRepository#memoize #510

NicklasWallgren opened this issue Jul 3, 2024 · 0 comments

Comments

@NicklasWallgren
Copy link
Contributor

NicklasWallgren commented Jul 3, 2024

There is a risk that initialized is cached between threads, leading to multiple initializations.

Explaination;

  1. Thread 1 calls get and enters the firstTime method.
  2. Before firstTime completes, Thread 2 calls get.
  3. Since initialized might not be updated yet (due to thread interleaving), Thread 2 might also enter the firstTime method.
  4. Both threads could end up calling the original supplier and setting delegate and initialized, leading to multiple initializations.

Fix;
Make initialized and delegate volatile to ensure visibility across threads.

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

No branches or pull requests

1 participant