quickwit-oss/quickwit · error

subscription map should exist

Error message

subscription map should exist

What it means

subscribe_aux inserts an EventSubscriptions<E> map into the broker's AnyMap immediately before reading it back; this expect asserts that insert succeeded. Failing means the type-keyed map bookkeeping is broken — an internal invariant violation, not a user-triggerable condition in normal use.

Solutions

  1. Verify the insert::<EventSubscriptions<E>> call on the preceding lines was not removed or conditioned by a code change
  2. Check for concurrent code that removes entries from the subscriptions AnyMap
  3. Run the pubsub unit tests to confirm broker initialization
  4. Report/regress-fix in quickwit-common::pubsub; no user-side workaround exists

Example fix

// before
subscriptions.insert::<EventSubscriptions<E>>(HashMap::new());
let typed = subscriptions.get_mut::<EventSubscriptions<E>>().expect("subscription map should exist");
// after: fail loudly with context if entry absent
let typed = match subscriptions.get_mut::<EventSubscriptions<E>>() { Some(t) => t, None => panic!("EventSubscriptions map missing after insert for event type {}", std::any::type_name::<E>()) };
Defensive patterns

Strategy: type-guard

Validate before calling

// Check map presence before insert/get
if subscriptions.get::<EventSubscriptions<E>>().is_none() { subscriptions.insert::<EventSubscriptions<E>>(HashMap::new()); }

Type guard

fn typed_map_present<E: Event>(m: &AnyMap) -> bool { m.get::<EventSubscriptions<E>>().is_some() }

Try / catch

let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| broker.subscribe(subscriber)));
if result.is_err() { /* broker internals corrupted — recreate broker */ }

Prevention

When it happens

Trigger: Calling subscribe/subscribe_without_timeout when the preceding subscriptions.insert::<EventSubscriptions<E>>(HashMap::new()) did not take effect — only possible if the AnyMap entry was concurrently removed or the insert logic regressed.

Common situations: Practically unreachable in correct code; encountered after modifying pubsub.rs internals, or from concurrent mutation bugs introduced by custom patches to the broker.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of quickwit-oss/quickwit@a39730c5cd (2026-09-08). Data as JSON: /api/errors/1e0c1c1cd37a28e7. Report an issue: GitHub.

Appendix: source

Thrown at quickwit/quickwit-common/src/pubsub.rs:99

            .expect("lock should not be poisoned");

        if !subscriptions.contains::<EventSubscriptions<E>>() {
            subscriptions.insert::<EventSubscriptions<E>>(HashMap::new());
        }
        let subscription_id = self
            .inner
            .subscription_sequence
            .fetch_add(1, Ordering::Relaxed);

        let subscriber_name = std::any::type_name::<S>();
        let subscription = EventSubscription {
            subscriber_name,
            subscriber: Arc::new(TokioMutex::new(Box::new(subscriber))),
            with_timeout,
        };
        let typed_subscriptions = subscriptions
            .get_mut::<EventSubscriptions<E>>()
            .expect("subscription map should exist");
        typed_subscriptions.insert(subscription_id, subscription);

        EventSubscriptionHandle {
            subscription_id,
            broker: Arc::downgrade(&self.inner),
            drop_me: |subscription_id, broker| {
                let mut subscriptions = broker
                    .subscriptions
                    .lock()
                    .expect("lock should not be poisoned");
                if let Some(typed_subscriptions) = subscriptions.get_mut::<EventSubscriptions<E>>()
                {
                    typed_subscriptions.remove(&subscription_id);
                }
            },
        }
    }

View on GitHub (pinned to a39730c5cd)