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

cancelAndWait on or triggers deadlock #516

Closed
etan-status opened this issue Mar 2, 2024 · 0 comments
Closed

cancelAndWait on or triggers deadlock #516

etan-status opened this issue Mar 2, 2024 · 0 comments

Comments

@etan-status
Copy link
Contributor

this leads to deadlock:

import chronos

proc f(): Future[void] {.async.} =
  await sleepAsync(10.seconds) or sleepAsync(5.seconds)

proc g(): Future[void] {.async.} =
  let fx = f()
  await fx.cancelAndWait()

waitFor g()

echo "ok"

this works fine:

import chronos

proc f(): Future[void] {.async.} =
  discard await race(sleepAsync(10.seconds), sleepAsync(5.seconds))

proc g(): Future[void] {.async.} =
  let fx = f()
  await fx.cancelAndWait()

waitFor g()

echo "ok"
etan-status added a commit to vacp2p/nim-libp2p that referenced this issue Mar 2, 2024
`or` futures are currently bugged when using `cancelAndWait` on them.
This sometimes show when tests run several minutes longer until the
mess is unstucked through a timeout that pokes the machinery again.
Use `race` to avoid the lockup.

- status-im/nim-chronos#516
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

2 participants