Skip to content

Fix ReclaimFunds hanging forever when the context is cancelled mid-sweep - #276

Draft
damilolaedwards wants to merge 1 commit into
ethpandaops:masterfrom
damilolaedwards:fix/reclaimfunds-oncomplete-skip-on-cancel
Draft

Fix ReclaimFunds hanging forever when the context is cancelled mid-sweep#276
damilolaedwards wants to merge 1 commit into
ethpandaops:masterfrom
damilolaedwards:fix/reclaimfunds-oncomplete-skip-on-cancel

Conversation

@damilolaedwards

Copy link
Copy Markdown
Contributor

Summary

  • OnComplete is documented as always being called once transaction processing finishes, regardless of success or failure. The guard that returns early when the context is already cancelled skipped that contract entirely, returning before the callback was ever wired up.
  • ReclaimFunds depends on that contract: it fires one goroutine per wallet to send a reclaim transaction and only calls wg.Done() from inside OnComplete, then waits on the group. Both a daemon shutdown and a spammer pause cancel the same context passed down to these sends, so any reclaim still being dispatched at that moment would never release its slot in the wait group, leaving the whole reclaim, and the spammer run it belongs to, stuck forever with no timeout to recover.
  • The early-return path now calls OnComplete with the context error before returning, so every caller relying on it firing keeps working correctly once the context is cancelled.

Test plan

  • Added a test driving the real transaction submission path with an already-cancelled context, asserting OnComplete still fires.
  • Added a test mirroring ReclaimFunds's own wait group wiring end to end, confirming it no longer hangs.
  • Both verified to fail against the previous behavior and pass with the fix, under -race.

OnComplete is documented as always being called once transaction
processing finishes, regardless of success or failure. The guard that
returns early when the context is already cancelled skipped that
contract entirely, returning before the callback was ever wired up.

ReclaimFunds depends on that contract: it fires one goroutine per
wallet to send a reclaim transaction and only calls wg.Done() from
inside OnComplete, then waits on the group. Both a daemon shutdown and
a spammer pause cancel the same context that gets passed down to these
sends, so any reclaim still being dispatched at that moment would never
release its slot in the wait group, leaving the whole reclaim, and the
spammer run it belongs to, stuck forever with no timeout to recover.

Now the early-return path calls OnComplete with the context error
before returning, so every caller that relies on it firing keeps
working correctly once the context is cancelled.

Added tests that drive the real SendTransaction path with an
already-cancelled context, one asserting OnComplete still fires, and
one mirroring ReclaimFunds's own wait group wiring end to end.
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.

1 participant