{"record":{"id":"2eaa445028221689","repo":"databendlabs/databend","slug":"failed-to-send-log-element","errorCode":null,"errorMessage":"Failed to send log element: {}","messagePattern":"Failed to send log element: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/common/tracing/src/remote_log.rs","lineNumber":309,"sourceCode":"                    }\n                    self.collect()?;\n                    break;\n                }\n                Err(last_collect) => {\n                    if now - self.interval < last_collect {\n                        break;\n                    }\n                    current_last_collect = last_collect;\n                }\n            }\n        }\n        Ok(())\n    }\n\n    pub fn collect(&self) -> anyhow::Result<()> {\n        self.sender\n            .send_blocking(LogMessage::Flush(Vec::from_iter(self.queue.try_iter())))\n            .map_err(|e| anyhow::anyhow!(\"Failed to send log element: {}\", e))?;\n        Ok(())\n    }\n\n    pub fn force_collect(&self) {\n        let (tx, rx) = channel();\n        if self\n            .sender\n            .send_blocking(LogMessage::ForceFlush(\n                Vec::from_iter(self.queue.try_iter()),\n                tx,\n            ))\n            .is_ok()\n        {\n            let _ = rx.recv_timeout(Duration::from_secs(3));\n        }\n    }\n}\n","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/common/tracing/src/remote_log.rs#L291-L327","documentation":"collect() drains the queued log elements and sends a LogMessage::Flush over sender using send_blocking. If the receiver end (the remote log flusher task) is gone or the blocking send fails, this error is returned. It indicates accumulated log elements could not be delivered for remote storage.","triggerScenarios":"Calling collect() (directly or via log -> force_collect path) after the receiving task was dropped or its channel closed; send_blocking failing during shutdown or when the runtime worker panicked.","commonSituations":"Tearing down the tracing/remote-log pipeline while flush is still in flight; background task aborted due to runtime shutdown; queue backpressure combined with a dead consumer.","solutions":["Check the wrapped error to confirm the channel is disconnected (SendError).","Keep the consumer task alive until after a final collect()/force_collect() during graceful shutdown.","Use force_collect() with its completion channel to await the flush and detect shutdown ordering issues.","Drop the log pipeline before or after all producers deterministically, matching the lifecycle of the subscriber."],"exampleFix":"// before\nself.sender.send_blocking(LogMessage::Flush(...))\n    .map_err(|e| anyhow::anyhow!(\"Failed to send log element: {}\", e))?;\n// after\nmatch self.sender.send_blocking(LogMessage::Flush(...)) {\n    Ok(()) => (),\n    Err(e) if e.is_disconnected() => eprintln!(\"remote log consumer gone; dropping {} elements\", self.queue.len()),\n    Err(e) => return Err(anyhow::anyhow!(\"Failed to send log element: {}\", e)),\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match collector.collect() {\n    Ok(()) => (),\n    Err(e) => eprintln!(\"flush failed, {} elements lost: {e}\", queue_len),\n}","preventionTips":["Perform a final force_collect()/collect() during graceful shutdown before dropping the consumer","Join the flusher task before process exit","Bound the queue and alert on persistent send failures"],"tags":["rust","tracing","channel","logging"],"backgroundTag":"broken-pipe","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}