Skip to content

fix(purchasing): fix crash completing future more than once #1249

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

Merged
merged 1 commit into from
Jun 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions codex/purchasing/states/submitted.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ method run*(
requestId = purchase.requestId

proc wait() {.async.} =
let done = newFuture[void]()
let done = newAsyncEvent()
proc callback(_: RequestId) =
done.complete()
done.fire()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the callback supposed to be called more than once, if not this is probably an issue somewhere else?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. This smells like a subscription callback or ethers error, or maybe the event is indeed being fired more than once in the contract.

The root issue will be masked by this change. I don't think it's a big deal personally, but it could potentially hide other issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that it should not be called more than once. However it might be called more than once if the JSON-RPC provider decides to invoke the callback more than once for whatever reason (chain reorg?), so we'd better not crash if it does 😄


let subscription = await market.subscribeFulfillment(request.id, callback)
await done
await done.wait()
await subscription.unsubscribe()

proc withTimeout(future: Future[void]) {.async.} =
Expand Down
Loading