Fix: Prevent duplicate activation race condition #2543
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Prevent duplicate activation race condition (Issue #2257)
Problem
The activator has two independent triggers for entity activation:
websocket_task- real-time blockchain eventsget_snapshot_poll- 60-second polling snapshotBoth can observe the same entity with
status=Pendingand enqueue it to thesame
mpsc::channel(128)queue. The single-threaded processor then receivesboth events sequentially, causing:
ActivateUserTX successfullyPendingstatus from queue, allocatesmore resources, sends duplicate TX which fails with
InvalidStatusbecause on-chain status is already
ActivatedSolution
Add an in-flight guard at the dispatcher level (
Processor::process_event)that tracks which pubkeys are currently being processed:
HashSet<Pubkey>tracks in-flight entitiesPending/Updatingstates, check if already in-flightThis prevents resource waste and duplicate on-chain calls while preserving the
existing
InvalidStatushandling as a safety-net fallback.Metrics Added
doublezero_activator_duplicate_event_skipped{entity_type=user|link}-counts events skipped by in-flight guard (expect this to increment during
normal operation)
doublezero_activator_invalid_status_encountered{entity_type=user|link}-counts on-chain InvalidStatus errors (should be rare now, indicates guard
missed something)
Testing