{"record":{"id":"3d278e56fdc21594","repo":"astral-sh/ruff","slug":"failed-to-send-notification-method-method-er","errorCode":null,"errorMessage":"Failed to send notification (method={method}): {error}","messagePattern":"Failed to send notification \\(method=(.+?)\\): (.+?)","errorType":"console","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/ruff_server/src/session/client.rs","lineNumber":106,"sourceCode":"                format!(\"Failed to send request method={method}\", method = R::METHOD)\n            })?;\n\n        Ok(())\n    }\n\n    /// Sends a notification to the client.\n    pub(crate) fn send_notification<N>(&self, params: N::Params) -> crate::Result<()>\n    where\n        N: lsp_types::Notification,\n    {\n        let method = N::METHOD.to_string();\n\n        self.client_sender\n            .send(lsp_server::Message::Notification(Notification::new(\n                method, params,\n            )))\n            .map_err(|error| {\n                anyhow!(\n                    \"Failed to send notification (method={method}): {error}\",\n                    method = N::METHOD\n                )\n            })\n    }\n\n    /// Sends a notification without any parameters to the client.\n    ///\n    /// This is useful for notifications that don't require any data.\n    #[expect(dead_code)]\n    fn send_notification_no_params(&self, method: &str) -> crate::Result<()> {\n        self.client_sender\n            .send(lsp_server::Message::Notification(Notification::new(\n                method.to_string(),\n                Value::Null,\n            )))\n            .map_err(|error| anyhow!(\"Failed to send notification (method={method}): {error}\"))\n    }","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/astral-sh/ruff/blob/d1087a4b9e03d253a88703f34e0869ee4b805456/crates/ruff_server/src/session/client.rs#L88-L124","documentation":"The server sends client notifications (publishDiagnostics, logMessage, ...) by pushing them onto an internal channel read by the main loop, which writes to the actual transport. If that channel is already closed — the main loop has exited because the transport broke or the server is shutting down — the send fails and this error is logged with the method name.","triggerScenarios":"A background task (e.g., a queued lint run) finishing after the client disconnected and the main loop exited; races during shutdown where diagnostics publishing overlaps server teardown; transport errors (broken pipe on stderr/stdout) killing the main loop first.","commonSituations":"Editor crashes or force-closes while background lint/format tasks are in flight; aggressive process supervision restarting the server; noisy logs during teardown that look like real failures.","solutions":["Treat it as expected noise during shutdown: restart the server and verify it reconnects cleanly","If it recurs mid-session, check the transport (stderr/stdout pipes not blocked or closed early) and for earlier errors in the log that killed the main loop","Reduce late work by letting in-flight background tasks drain before exiting (graceful shutdown)","Update the server — shutdown-ordering improvements land regularly"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Rust: a failed notification send during teardown is not fatal\nif let Err(e) = client.send_notification::<lsp_types::notification::PublishDiagnostics>(params) {\n    tracing::warn!(%e, \"dropping notification; main loop likely exited\");\n}","preventionTips":["Treat send failures after the main loop exits as expected shutdown noise","Drain or cancel background tasks before dropping the main loop","Keep the transport healthy (dedicated stdout for LSP, logs to stderr) so the loop does not die early"],"tags":["lsp","channel","transport","shutdown","ruff-server"],"backgroundTag":"message-channel-send-failed","analyzedSha":"d1087a4b9e03d253a88703f34e0869ee4b805456","analyzedAt":"2026-08-20T16:33:49.445Z","contentChangedAt":"2026-08-20T16:33:49.445Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}