{"record":{"id":"5e2a95e8f67b0907","repo":"gleam-lang/gleam","slug":"beam-compiler-instance-exited-status","errorCode":null,"errorMessage":"BEAM compiler instance exited: {status}","messagePattern":"BEAM compiler instance exited: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler-cli/src/beam_compiler.rs","lineNumber":45,"sourceCode":"    // A guard held for cleaning up the temporary file used to start the BEAM instance.\n    _source: tempfile::NamedTempFile,\n}\n\nimpl BeamCompilerInstance {\n    pub fn compile(\n        &mut self,\n        out: &Utf8Path,\n        lib: &Utf8Path,\n        modules: &HashSet<Utf8PathBuf>,\n        stdio: Stdio,\n    ) -> Result<Vec<String>, Error> {\n        // Check that the BEAM instance is still alive before attempting to use it.\n        let exit_status = self\n            .process\n            .try_wait()\n            .expect(\"access BEAM instance exit state\");\n        if let Some(status) = exit_status {\n            panic!(\"BEAM compiler instance exited: {status}\");\n        }\n\n        // Prepare work to send to the BEAM instance.\n        let args = format!(\n            \"{{\\\"{}\\\", \\\"{}\\\", [\\\"{}\\\"]}}\",\n            escape_path(lib),\n            escape_path(out.join(\"ebin\")),\n            modules\n                .iter()\n                .map(|module| escape_path(out.join(paths::ARTEFACT_DIRECTORY_NAME).join(module)))\n                .join(\"\\\", \\\"\")\n        );\n\n        tracing::debug!(args=?args, \"call_beam_compiler\");\n\n        writeln!(self.stdin.as_ref().expect(\"stdin present\"), \"{args}.\").map_err(|e| {\n            Error::ShellCommand {\n                program: \"escript\".into(),","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/gleam-lang/gleam/blob/7e623aa83da3776faee50ca4ab9a6c40124acd95/compiler-cli/src/beam_compiler.rs#L27-L63","documentation":"Gleam keeps one long-lived Erlang/BEAM helper process (an escript started by `BeamCompilerInstance::new`) to compile .erl modules quickly. Before every request `BeamCompilerInstance::compile` calls `try_wait()` (compiler-cli/src/beam_compiler.rs:40-46); if the child has already exited it panics `BEAM compiler instance exited: {status}`. This is a broken-invariant abort — the compiler assumes its helper survives the whole session — and it takes down the `gleam` process.","triggerScenarios":"The BEAM child dies between or during compile requests: the kernel OOM killer or a container memory limit kills escript, Erlang was uninstalled or corrupted while the session ran, security software kills the helper process, or the machine is unstable. (The adjacent `expect(\"access BEAM instance exit state\")` is a separate near-impossible waitpid failure.)","commonSituations":"CI containers with tight `--memory`/`--pids-limit`; Docker/gVisor sandboxes where escript crashes; antivirus reaping child processes on Windows; a partially upgraded Erlang install; a long-lived Gleam LSP session spanning an Erlang upgrade or outage.","solutions":["Verify Erlang works outside Gleam: `command -v escript` and `erl -noshell -eval 'io:format(\"ok~n\").' -s init stop`","Check for resource kills: `dmesg | grep -i -E 'oom|killed process'` or container runtime events; raise memory/pids limits","Re-run the command — a fresh `gleam` invocation spawns a new BEAM instance; for the LSP, restart the editor or language server","If it reproduces with healthy Erlang and no OOM, capture the exit status from the panic text and report it at https://github.com/gleam-lang/gleam/issues"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# verify Erlang can host the BEAM helper before building\ncommand -v escript >/dev/null 2>&1 || { echo 'escript not on PATH'; exit 1; }\nerl -noshell -eval 'io:format(\"erlang ok~n\").' -s init stop || { echo 'erl unusable'; exit 1; }\ngleam build","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin a known-good Erlang/OTP in CI (Gleam requires escript on PATH)","Leave memory headroom above Erlang's footprint so the OOM killer never targets escript","Restart the Gleam LSP after upgrading or removing Erlang so it re-spawns a fresh BEAM instance"],"tags":["gleam","erlang","beam","escript","subprocess","build"],"backgroundTag":"subprocess-exited-unexpectedly","analyzedSha":"7e623aa83da3776faee50ca4ab9a6c40124acd95","analyzedAt":"2026-08-17T00:07:02.091Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}