{"record":{"id":"6db072e80799577e","repo":"wezterm/wezterm","slug":"failed-to-re-exec","errorCode":null,"errorMessage":"failed to re-exec: {:?}","messagePattern":"failed to re-exec: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"wezterm-mux-server/src/main.rs","lineNumber":184,"sourceCode":"            cmd.creation_flags(winapi::um::winbase::DETACHED_PROCESS);\n            let child = cmd.spawn();\n            drop(child);\n            return Ok(());\n        }\n\n        #[cfg(unix)]\n        {\n            use std::os::unix::process::CommandExt;\n            if let Some(mask) = umask::UmaskSaver::saved_umask() {\n                unsafe {\n                    cmd.pre_exec(move || {\n                        libc::umask(mask);\n                        Ok(())\n                    });\n                }\n            }\n\n            return Err(anyhow::anyhow!(\"failed to re-exec: {:?}\", cmd.exec()));\n        }\n    }\n\n    // Remove some environment variables that aren't super helpful or\n    // that are potentially misleading when we're starting up the\n    // server.\n    // We may potentially want to look into starting/registering\n    // a session of some kind here as well in the future.\n    for name in &[\n        \"OLDPWD\",\n        \"PWD\",\n        \"SHLVL\",\n        \"WEZTERM_PANE\",\n        \"WEZTERM_UNIX_SOCKET\",\n        \"_\",\n    ] {\n        std::env::remove_var(name);\n    }","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/wezterm/wezterm/blob/3ff7522b9617ec920f7fbdb22b57e93d42d93ee9/wezterm-mux-server/src/main.rs#L166-L202","documentation":"When wezterm-mux-server runs with --daemonize on Unix it forks, then re-executes its own binary (std::env::current_exe(), passing --pid-file-fd) to reset the async runtime. Command::exec() replaces the process and only returns on failure, so reaching this line means exec itself failed; the io::Error is wrapped as 'failed to re-exec: {err:?}'. The daemon cannot start.","triggerScenarios":"The binary at current_exe() no longer exists or lost execute permission between start and re-exec (replaced build artifact, nix store GC, rust target dir clobbered, package upgrade mid-run); ENOMEM or a security policy (seccomp/AppArmor) blocking execve.","commonSituations":"Running wezterm-mux-server out of a target/ directory that a rebuild replaced; NixOS store garbage collection removing the running version; containers with restrictive seccomp profiles; moving/renaming the install prefix.","solutions":["Read the wrapped io::Error: ENOENT/EACCES mean the binary vanished or is not executable — reinstall/rebuild wezterm and start again","Install wezterm to a stable path and launch the daemon from there instead of a throwaway build dir","Run without --daemonize once to see the error directly and confirm exec works","If the error is ENOMEM or a sandbox denial, raise resource limits / adjust the seccomp or container profile to allow execve"],"exampleFix":"# before: daemonize straight out of a rebuildable dir\n/tmp/wezterm-build/target/debug/wezterm-mux-server --daemonize .  # -> failed to re-exec\n\n# after: install to a stable path first\ncp target/release/wezterm /usr/local/bin/ && /usr/local/bin/wezterm-mux-server --daemonize .","handlingStrategy":"try-catch","validationCode":"// before daemonizing, confirm we can still exec ourselves\nlet exe = std::env::current_exe()?;\nanyhow::ensure!(exe.is_file(), \"binary vanished: {}\", exe.display());","typeGuard":null,"tryCatchPattern":"This Err from main is terminal for the daemon: inspect the wrapped io::Error (ENOENT -> binary gone, EACCES -> permissions, ENOMEM -> resources); fix the install and relaunch rather than retrying in-process.","preventionTips":["Install wezterm to a stable path before running the daemon","Avoid daemonizing out of target/ or nix store paths that rebuilds/GC can replace","Watch for package upgrades that remove the running binary; restart the daemon after upgrades"],"tags":["mux","daemon","exec","unix","startup","wezterm"],"backgroundTag":"process-exec-failed","analyzedSha":"3ff7522b9617ec920f7fbdb22b57e93d42d93ee9","analyzedAt":"2026-08-20T04:47:31.434Z","contentChangedAt":"2026-08-20T04:47:31.434Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}