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

Cache#get can hang in case of interruption #172

Closed
ghostdogpr opened this issue Feb 18, 2025 · 0 comments · Fixed by #174
Closed

Cache#get can hang in case of interruption #172

ghostdogpr opened this issue Feb 18, 2025 · 0 comments · Fixed by #174

Comments

@ghostdogpr
Copy link
Member

Had a production incident because Cache#get was hanging forever. Finally found the culprit: when get is interrupted, there is a possibility for it to be interrupted before onInterrupt is set but after the map is updated with the Pending state. In that case it stays Pending until the cache is invalidated.

Reproducer:

    test("ensure get is not hanging when we interrupt right after a get in another fiber") {
      for {
        cache <- Cache.make(10, Duration.Infinity, Lookup((_: Unit) => ZIO.succeed(1)))
        task1  = (cache.invalidate(()) *> cache.get(())).fork.flatMap(_.interrupt)
        _     <- ZIO.forkAll(List.fill(1000)(task1))
        _     <- cache.get(()).exit.timeoutFail("hanging")(3.seconds).forever.timeout(7.seconds)
      } yield assertCompletes
    } @@ TestAspect.withLiveClock
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 a pull request may close this issue.

1 participant