Skip to content

Prevent head-change broadcast overflow by migrating to async-broadcast #7442

Description

@coderabbitai

Summary

The head-change broadcast channel can overwrite unread updates when a consumer falls behind. This can leave an index incomplete or stale.

Migrate the head-change publication mechanism to async-broadcast and disable overflow.

Rationale

The NoSQL index has the same risk at src/daemon/db_util.rs near Line 833. The SQLite chain indexer introduced in #6720 also consumes head changes. A lagging consumer must not silently lose head-change updates.

Affected areas

  • src/daemon/db_util.rs head-change publication and NoSQL index consumption.
  • SQLite chain indexer head-change consumption in src/chain/store/indexer.rs.
  • Any other consumers of the same head-change channel.

Required changes

  1. Replace the applicable Tokio broadcast channel with async-broadcast.
  2. Configure the channel so that sends do not discard unread messages on overflow.
  3. Update all producers and consumers for the new channel API.
  4. Define and implement shutdown behavior so blocked senders or receivers can exit cleanly.

Acceptance criteria

  • A slow index consumer does not lose head-change updates because of channel-buffer overflow.
  • Both the NoSQL index and SQLite chain indexer continue to process ordered head changes.
  • Tests cover a consumer that falls behind the configured channel capacity.
  • Shutdown does not leave channel tasks blocked.

Requested by: @hanabi1224

Backlinks:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions