{"record":{"id":"1e0c1c1cd37a28e7","repo":"quickwit-oss/quickwit","slug":"subscription-map-should-exist","errorCode":null,"errorMessage":"subscription map should exist","messagePattern":"subscription map should exist","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quickwit/quickwit-common/src/pubsub.rs","lineNumber":99,"sourceCode":"            .expect(\"lock should not be poisoned\");\n\n        if !subscriptions.contains::<EventSubscriptions<E>>() {\n            subscriptions.insert::<EventSubscriptions<E>>(HashMap::new());\n        }\n        let subscription_id = self\n            .inner\n            .subscription_sequence\n            .fetch_add(1, Ordering::Relaxed);\n\n        let subscriber_name = std::any::type_name::<S>();\n        let subscription = EventSubscription {\n            subscriber_name,\n            subscriber: Arc::new(TokioMutex::new(Box::new(subscriber))),\n            with_timeout,\n        };\n        let typed_subscriptions = subscriptions\n            .get_mut::<EventSubscriptions<E>>()\n            .expect(\"subscription map should exist\");\n        typed_subscriptions.insert(subscription_id, subscription);\n\n        EventSubscriptionHandle {\n            subscription_id,\n            broker: Arc::downgrade(&self.inner),\n            drop_me: |subscription_id, broker| {\n                let mut subscriptions = broker\n                    .subscriptions\n                    .lock()\n                    .expect(\"lock should not be poisoned\");\n                if let Some(typed_subscriptions) = subscriptions.get_mut::<EventSubscriptions<E>>()\n                {\n                    typed_subscriptions.remove(&subscription_id);\n                }\n            },\n        }\n    }\n","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/quickwit-oss/quickwit/blob/a39730c5cdcd1a4fe798403737ae293999ea21f8/quickwit/quickwit-common/src/pubsub.rs#L81-L117","documentation":"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.","triggerScenarios":"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.","commonSituations":"Practically unreachable in correct code; encountered after modifying pubsub.rs internals, or from concurrent mutation bugs introduced by custom patches to the broker.","solutions":["Verify the insert::<EventSubscriptions<E>> call on the preceding lines was not removed or conditioned by a code change","Check for concurrent code that removes entries from the subscriptions AnyMap","Run the pubsub unit tests to confirm broker initialization","Report/regress-fix in quickwit-common::pubsub; no user-side workaround exists"],"exampleFix":"// before\nsubscriptions.insert::<EventSubscriptions<E>>(HashMap::new());\nlet typed = subscriptions.get_mut::<EventSubscriptions<E>>().expect(\"subscription map should exist\");\n// after: fail loudly with context if entry absent\nlet 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>()) };","handlingStrategy":"type-guard","validationCode":"// Check map presence before insert/get\nif subscriptions.get::<EventSubscriptions<E>>().is_none() { subscriptions.insert::<EventSubscriptions<E>>(HashMap::new()); }","typeGuard":"fn typed_map_present<E: Event>(m: &AnyMap) -> bool { m.get::<EventSubscriptions<E>>().is_some() }","tryCatchPattern":"let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| broker.subscribe(subscriber)));\nif result.is_err() { /* broker internals corrupted — recreate broker */ }","preventionTips":["Keep insert and get_mut for the same type key adjacent and unconditional","Add unit tests covering subscribe for multiple event types","Avoid manual edits to the AnyMap bookkeeping in pubsub.rs","Treat this panic as a code regression signal, not a runtime condition"],"tags":["rust","invariant","pubsub","anymap"],"backgroundTag":"internal-invariant-violation","analyzedSha":"a39730c5cdcd1a4fe798403737ae293999ea21f8","analyzedAt":"2026-09-08T13:19:37.784Z","contentChangedAt":"2026-09-08T13:19:37.784Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}