{"record":{"id":"dc90f690f8697acc","repo":"facebook/flow","slug":"failed-to-spawn-lsp-log-flusher","errorCode":null,"errorMessage":"failed to spawn LSP log flusher","messagePattern":"failed to spawn LSP log flusher","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"rust_port/crates/flow_lsp_server/src/flow_lsp.rs","lineNumber":719,"sourceCode":"pub fn log_flusher_run() {\n    std::thread::Builder::new()\n        .name(\"flow_lsp_log_flusher\".to_string())\n        .spawn(|| {\n            loop {\n                std::thread::sleep(Duration::from_secs(5));\n                let event_logger_result = flow_tokio_runtime::block_on(async {\n                    let event_logger_flush = flow_event_logger_lwt::flush();\n                    let interaction_flush = crate::lsp_interaction::flush();\n                    let (event_logger_result, ()) =\n                        tokio::join!(event_logger_flush, interaction_flush);\n                    event_logger_result\n                });\n                if let Err(err) = event_logger_result {\n                    eprintln!(\"Failed to flush Flow event logs: {}\", err);\n                }\n            }\n        })\n        .expect(\"failed to spawn LSP log flusher\");\n}\n\nuse flow_lsp::lsp_fmt;\n\nuse crate::jsonrpc::get_next_request_id;\nuse crate::lsp_interaction;\n\nfn sys_utils_realpath(path: &str) -> Option<String> {\n    flow_common::files::cached_canonicalize(std::path::Path::new(path))\n        .ok()\n        .map(|p| p.to_string_lossy().to_string())\n}\n\nfn json_truncate(\n    json: &serde_json::Value,\n    max_string_length: usize,\n    max_child_count: usize,\n) -> serde_json::Value {","sourceCodeStart":701,"sourceCodeEnd":737,"githubUrl":"https://github.com/facebook/flow/blob/5c865861998a8ccb7dbc82b0c1f511e9ef60c3d9/rust_port/crates/flow_lsp_server/src/flow_lsp.rs#L701-L737","documentation":"The LSP server spawns a background thread that periodically flushes Flow event logs; .expect(\"failed to spawn LSP log flusher\") panics if std::thread::Builder::spawn fails. spawn only fails when the OS cannot create a thread — resource limits (RLIMIT_NPROC, cgroup pids.max) or memory exhaustion. Without this thread, event logs would never be flushed, so the server aborts at startup.","triggerScenarios":"Starting the Flow LSP server (flow_lsp.rs startup path) in a process that has exhausted its thread/process allowance or cannot allocate the thread stack.","commonSituations":"Editor-launched LSP servers inside containers with strict pids.max; many concurrent LSP sessions in CI hitting RLIMIT_NPROC; low ulimit -u on macOS/Linux dev machines; memory pressure on large monorepo workstations.","solutions":["Raise the process/thread limit: ulimit -u higher, or --pids-limit / cgroup pids.max in containers.","Reduce the number of concurrent LSP/server processes running simultaneously.","Increase available memory or the stack allocation environment if spawn fails due to ENOMEM.","Verify with `ulimit -u` and `cat /proc/sys/kernel/threads-max`, then restart the editor/LSP client."],"exampleFix":"// before (systemd user service / container)\nTasksMax=128\n// after\nTasksMax=4096   # or: docker run --pids-limit=4096","handlingStrategy":"fallback","validationCode":"fn can_spawn_thread() -> bool {\n    std::thread::Builder::new().spawn(|| {}).map(|h| { let _ = h.join(); true }).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match std::panic::catch_unwind(start_flow_lsp) {\n    Ok(_) => {},\n    Err(_) => eprintln!(\"LSP failed to start: raise ulimit -u / pids.max\"),\n}","preventionTips":["Raise TasksMax/pids-limit for services and containers that host the LSP server.","Avoid running dozens of LSP sessions concurrently on limited machines.","Check ulimit -u before launching editors in constrained environments.","Provision adequate memory for large-monorepo language server workloads."],"tags":["thread-spawn","resource-limits","lsp","panic","startup"],"backgroundTag":"unsupported-platform","analyzedSha":"5c865861998a8ccb7dbc82b0c1f511e9ef60c3d9","analyzedAt":"2026-09-08T04:32:53.179Z","contentChangedAt":"2026-09-08T04:32:53.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}