Skip to content

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

Open
vwinee21 wants to merge 2 commits into
stacks-network:master-20260727from
vwinee21:fix/dedup-event-observer-endpoint
Open

fix: deduplicate STACKS_EVENT_OBSERVER endpoint already registered in config file#7204
vwinee21 wants to merge 2 commits into
stacks-network:master-20260727from
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.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@federico-stacks
federico-stacks self-requested a review August 5, 2026 11:17

@federico-stacks federico-stacks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@vwinee21 Thanks for your contribution, and apologies for the delayed review.

A couple of general items first:

  • Please rebase the PR onto the main branch.
  • Please add a changelog entry following the instructions in changelog.d/README.md. You can also find examples from other PRs in that directory.

The fix is close, but I suggest one behavioral change: instead of discarding the environment-variable observer when its endpoint already exists, merge AnyEvent into the existing observer’s events_keys if it is not already present. This preserves the behavior requested through STACKS_EVENT_OBSERVER while still ensuring that the endpoint is registered only once and does not receive duplicate notifications. The existing TOML timeout and retry settings should be preserved.

Could you also add unit tests covering at least these cases?

  • The same endpoint with narrower TOML subscriptions gains AnyEvent and remains a single observer.
  • An endpoint already containing AnyEvent remains unchanged and is not duplicated.
  • Different endpoints remain registered separately.

@federico-stacks federico-stacks self-assigned this Aug 7, 2026
@dhaney-stacks

Copy link
Copy Markdown
Collaborator

I merged latest into the PR, but @vwinee21 you still need to sign the CLA and respond to @federico-stacks's feedback. Thanks.

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

4 participants