{"record":{"id":"ceebefe88210f22c","repo":"zed-industries/zed","slug":"socket-closed-before-a-message-was-received","errorCode":null,"errorMessage":"Socket closed before a message was received","messagePattern":"Socket closed before a message was received","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/etw_tracing/etw_tracing.rs","lineNumber":667,"sourceCode":"#[derive(Debug, serde::Serialize, serde::Deserialize)]\n#[serde(tag = \"type\")]\npub enum Command {\n    Save,\n    Cancel,\n}\n\nfn send_json<T: serde::Serialize>(writer: &mut impl Write, value: &T) -> Result<()> {\n    let json = serde_json::to_string(value).context(\"Serialize message\")?;\n    writeln!(writer, \"{json}\").context(\"Write to socket\")?;\n    writer.flush().context(\"Flush socket\")?;\n    Ok(())\n}\n\nfn recv_json<T: serde::de::DeserializeOwned>(reader: &mut impl BufRead) -> Result<T> {\n    let mut line = String::new();\n    reader.read_line(&mut line).context(\"Read from socket\")?;\n    if line.is_empty() {\n        bail!(\"Socket closed before a message was received\");\n    }\n    serde_json::from_str(line.trim()).context(\"Parse message\")\n}\n","sourceCodeStart":649,"sourceCodeEnd":671,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/etw_tracing/etw_tracing.rs#L649-L671","documentation":"recv_json() is the JSON-line protocol reader for the ETW Unix socket. read_line() returned zero bytes, which is EOF: the peer closed the socket without writing a status message. In the parent this surfaces (wrapped as 'Wait for Started status') when the elevated recording subprocess connects via accept() but then exits or crashes before/at sending StatusMessage::Started; in the child it occurs when the parent disappears.","triggerScenarios":"(1) launch_etw_recording(): elevated Zed child connects, then dies (panic, early exit, crash in WPR/COM before send_json(Started)) leaving the parent to read EOF. (2) receive_command() in the elevated child when the parent process is killed while the child waits for Save/Stop commands (there it is downgraded to a timed-out Save).","commonSituations":"Elevated child crashing during WPR startup (panic before the first send_json), UAC elevation launching an exe that immediately terminates (e.g. broken install, missing DLLs), the child being killed by antivirus/EDR, or the socket file at %TEMP%/zed-etw-<pid>.sock being removed. Distinguish from error 260: here the child said nothing at all.","solutions":["Check the elevated child's logs/stderr - it died before reporting anything; look for panic messages or DLL/load errors in the Zed log","Re-run the recording once to rule out a transient crash during WPR start","Verify the Zed exe that gets elevated is intact (std::env::current_exe() is what ShellExecuteW relaunches; a corrupted/half-updated binary dies instantly)","Exclude/allow the Zed binary in antivirus/EDR if it is killing the elevated child","If the child is crashing reproducibly in record_etw_trace, report a Zed bug with the panic backtrace"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match launch_etw_recording(heap_pid, output_path) {\n    Ok(session) => Ok(session),\n    Err(err) if err.to_string().contains(\"Socket closed before a message was received\") => {\n        // child died silently: check crash logs, offer one retry\n        check_elevated_child_logs();\n        retry_once()\n    }\n    Err(err) => Err(err),\n}","preventionTips":["Log the elevated child's stderr/panics somewhere the parent can point the user at","Retry once on EOF - child crashes during WPR startup are occasionally transient","Distinguish EOF (child said nothing) from Error status (child reported a reason) when triaging"],"tags":["windows","etw","unix-socket","eof","ipc","subprocess-crash"],"backgroundTag":"socket-eof-peer-disconnected","analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}