Skip to content

bug: a polled event can replay after restart #143

Backlog

Description

@ovitrif

EventQueue::add_event and event_handled encode the queue snapshot under the queue mutex, then call persist_queue after releasing it. VssStore::write takes the write version when it is called, so if a consumer reads the new event with next_event(), handles it, and calls event_handled() before the producer reaches KVStore::write, the producer's older snapshot (still holding the event) gets the higher version and becomes the persisted queue. A restart before the next queue write then replays the handled event.

next_event_async() only wakes after the producer's write completes, so this needs a polling consumer. Bitkit iOS polls next_event() because the async call cannot be cancelled from Swift (synonymdev/bitkit-ios#1395).

The window is the producer's synchronous path from dropping the lock to calling KVStore::write, so it is narrow, and handlers must already tolerate replayed events after a restart.

Fix: take the store write (and so its version) while the queue mutex is held, in add_event and event_handled.

Refs:

Activity

  1. added theissue type on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions