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

Conversation

markspanbroek
Copy link
Member

Fixes #962

Copy link
Contributor

@benbierens benbierens left a comment

Choose a reason for hiding this comment

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

\o/

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
Member 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 😄

Copy link
Contributor

@emizzle emizzle left a comment

Choose a reason for hiding this comment

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

Thanks Mark. As with #1248, this is a fix for preventing the node from crashing, but it doesn't quite explain why this subscription callback is being called twice. Therefore, I'd be hesitant to close #962 when merging this.

@markspanbroek
Copy link
Member Author

I took a look into market.nim the nim-ethers subscription handling, and a possible reason why it could be invoked more than once could be because of the resubscribing to events when we encounter an error in the JSON-RPC response when polling. A good fix for that would be to implement codex-storage/nim-ethers#96.

@markspanbroek markspanbroek enabled auto-merge June 4, 2025 11:27
@markspanbroek markspanbroek added this pull request to the merge queue Jun 4, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 4, 2025
@markspanbroek markspanbroek added this pull request to the merge queue Jun 4, 2025
Merged via the queue into master with commit ffbbee0 Jun 4, 2025
18 checks passed
@markspanbroek markspanbroek deleted the fix-future-crash branch June 4, 2025 15:19
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.

[BUG] Crash: attempt to complete future more than once.
4 participants