Skip to content

fix: deduplicate STACKS_EVENT_OBSERVER endpoint already registered in config file#7204

Open
vwinee21 wants to merge 1 commit into
stacks-network:masterfrom
vwinee21:fix/dedup-event-observer-endpoint
Open

fix: deduplicate STACKS_EVENT_OBSERVER endpoint already registered in config file#7204
vwinee21 wants to merge 1 commit into
stacks-network:masterfrom
vwinee21:fix/dedup-event-observer-endpoint

Conversation

@vwinee21
Copy link
Copy Markdown

Problem

Fixes #2810

When STACKS_EVENT_OBSERVER env var points to the same endpoint already registered in the events_observer TOML block, stacks-node inserts two EventObserverConfig entries into the HashSet — one with the events_keys from TOML, and one with AnyEvent from the env var.

Because EventObserverConfig derives Hash + Eq across all fields (endpoint, events_keys, timeout_ms, disable_retries), two configs with the same endpoint but different events_keys are considered distinct — both inserted, both receive broadcasts. The API server receives every event twice, causing it to fail over time.

Fix

Before inserting the env var observer, check if any existing observer already has the same endpoint. If found, emit a warn! log and skip the insert:

if let Ok(val) = std::env::var("STACKS_EVENT_OBSERVER") {
    if events_observers.iter().any(|o| o.endpoint == val) {
        warn!("STACKS_EVENT_OBSERVER endpoint '{}' is already registered via config file, skipping duplicate", val);
    } else {
        events_observers.insert(EventObserverConfig {
            endpoint: val,
            events_keys: vec![EventKeyType::AnyEvent],
            timeout_ms: 1_000,
            disable_retries: false,
        });
    }
};

Notes

  • Endpoint-only dedup: two configs with the same endpoint are always a misconfiguration regardless of events_keys difference.
  • A warn! log is emitted so operators are aware of the duplicate configuration.

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.

Duplicate events broadcasted to same API server

1 participant