Skip to content

Conversation

bitfaster
Copy link
Owner

@bitfaster bitfaster commented Jun 13, 2025

When called concurrently, AsyncAtomicFactory.GetValueAsync will enforce that one thread is calling the factory method.

Let's say

  • There are two threads, A and B, that both call GetValueAsync.
  • Thread A starts first
  • Thread B starts while thread A is running
  • Thread A throws an exception
  • Thread B should see the exception from Thread A

In other words, a second caller to GetValueAsync that overlaps the first should effectively queue on the same underlying task, and if the first throws, the second task should see that exception. This PR adds a test case to verify this.

By queuing on the same task like this, we mitigate lock convoys as discussed in #477.

@coveralls
Copy link

coveralls commented Jun 13, 2025

Coverage Status

coverage: 99.235% (+0.1%) from 99.118%
when pulling c0c2a99 on users/alexpeck/testatomfailure
into 5b2d64a on main.

@bitfaster bitfaster merged commit aefdf90 into main Jun 13, 2025
13 checks passed
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