{"record":{"id":"081192db04570028","repo":"vectordotdev/vector","slug":"mutex-poisoned-sink","errorCode":null,"errorMessage":"mutex poisoned","messagePattern":"mutex poisoned","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/sinks/websocket_server/sink.rs","lineNumber":411,"sourceCode":"                .message_buffering\n                .add_replay_message_id_to_event(&mut event);\n\n            let event_byte_size = event.estimated_json_encoded_size_of();\n\n            let mut bytes = BytesMut::new();\n            match self.encoder.encode(event, &mut bytes) {\n                Ok(()) => {\n                    finalizers.update_status(EventStatus::Delivered);\n\n                    let message = if encode_as_binary {\n                        Message::binary(bytes)\n                    } else {\n                        Message::text(String::from_utf8_lossy(&bytes))\n                    };\n                    let message_len = message.len();\n\n                    if self.message_buffering.should_buffer() {\n                        let mut buffer = message_buffer.lock().expect(\"mutex poisoned\");\n                        if buffer.len() + 1 >= buffer.capacity() {\n                            buffer.pop_front();\n                        }\n                        buffer.push_back((message_id, message.clone()));\n                    }\n\n                    let peers = peers.lock().expect(\"mutex poisoned\");\n                    let broadcast_recipients = peers.values();\n                    for recp in broadcast_recipients {\n                        if let Err(error) = recp.unbounded_send(message.clone()) {\n                            emit!(WebSocketListenerSendError {\n                                error: Box::new(error)\n                            });\n                        } else {\n                            events_sent.emit(CountByteSize(1, event_byte_size));\n                            bytes_sent.emit(ByteSize(message_len));\n                        }\n                    }","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/src/sinks/websocket_server/sink.rs#L393-L429","documentation":"The websocket_server sink run loop locks the message_buffering Mutex and unwraps the result with expect(\"mutex poisoned\"). A Mutex is poisoned when another thread panicked while holding the lock; every subsequent lock attempt then returns PoisonError and this expect panics in turn, cascading the original panic.","triggerScenarios":"Any panic occurring in a task/thread that previously held message_buffer while it was locked (e.g. during buffer manipulation), followed by the sink run loop trying to lock the same buffer when should_buffer() is true.","commonSituations":"An earlier panic in message serialization/formatting inside the buffered section; long-running Vector instances where one poisoned lock cascades shutdown of the whole sink task.","solutions":["Find and fix the original panic that poisoned the mutex (search logs for the first panic before this one).","Use lock().unwrap_or_else(|e| e.into_inner()) to recover the buffer data instead of propagating poisoning.","Reduce panic sources inside the critical section (avoid unwrap/expect on message formatting there).","Switch to a parking_lot::Mutex, which is not poisoned."],"exampleFix":"// before\nlet mut buffer = message_buffer.lock().expect(\"mutex poisoned\");\n// after\nlet mut buffer = message_buffer.lock().unwrap_or_else(|e| e.into_inner());","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"let mut buffer = message_buffer.lock().unwrap_or_else(|e| e.into_inner());","preventionTips":["Avoid panics inside critical sections guarded by std Mutex.","Prefer parking_lot::Mutex in hot sink paths.","Investigate the first logged panic; poisoning is always secondary."],"tags":["rust","panic","mutex","concurrency","websocket"],"backgroundTag":"mutex-poisoned","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}