{"record":{"id":"fc7da781cd7c4843","repo":"atuinsh/atuin","slug":"process-with-current-pid-does-not-exist","errorCode":null,"errorMessage":"Process with current pid does not exist","messagePattern":"Process with current pid does not exist","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/atuin-common/src/shell.rs","lineNumber":45,"sourceCode":"}\n\n#[derive(Debug, Error, Serialize)]\npub enum ShellError {\n    #[error(\"shell not supported\")]\n    NotSupported,\n\n    #[error(\"failed to execute shell command: {0}\")]\n    ExecError(String),\n}\n\nimpl Shell {\n    #[must_use]\n    pub fn current() -> Self {\n        let sys = System::new_all();\n\n        let process = sys\n            .process(get_current_pid().expect(\"Failed to get current PID\"))\n            .expect(\"Process with current pid does not exist\");\n\n        let parent = sys\n            .process(process.parent().expect(\"Atuin running with no parent!\"))\n            .expect(\"Process with parent pid does not exist\");\n\n        let shell = parent.name().to_string_lossy().trim().to_lowercase();\n        let shell = shell.strip_prefix('-').unwrap_or(&shell);\n\n        Self::from_string(shell)\n    }\n\n    #[must_use]\n    pub fn from_env() -> Self {\n        std::env::var(\"ATUIN_SHELL\")\n            .map_or(Self::Unknown, |shell| Self::from_string(&shell.trim().to_lowercase()))\n    }\n\n    #[must_use]","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/atuinsh/atuin/blob/c0c717ab04c881764bcad4b3d169a507e2432643/crates/atuin-common/src/shell.rs#L27-L63","documentation":"After resolving the current PID, Shell::current looks it up in the sysinfo process table. If the OS reports a PID for this process but the table has no such entry, the expect panics with 'Process with current pid does not exist'. This is an internal consistency failure between the OS PID allocation and the snapshot taken by System::new_all().","triggerScenarios":"Calling Shell::current when the sysinfo System::new_all() snapshot misses the current process — e.g. the process exits during snapshotting, or the platform backend enumerates an incomplete process list.","commonSituations":"Race with process exit in short-lived hook invocations; sandboxed/containerized environments with restricted /proc visibility; sysinfo bugs on specific kernels.","solutions":["Retry the call — the race with process exit is transient.","Check that /proc is mounted and readable in the container/sandbox.","Update the sysinfo crate to a version fixing platform-specific process enumeration bugs.","Replace the expect with a fallback shell guess (e.g. $SHELL env var) in embedded usage."],"exampleFix":"// before\nlet process = sys.process(get_current_pid().expect(\"Failed to get current PID\"))\n    .expect(\"Process with current pid does not exist\");\n\n// after\nlet process = get_current_pid().ok().and_then(|pid| sys.process(pid))\n    .ok_or_else(|| std::env::var(\"SHELL\").unwrap_or_default().into())?;","handlingStrategy":"fallback","validationCode":"// Rust: pre-check the current pid is resolvable before relying on Shell::current\nlet pid_ok = sysinfo::get_current_pid().is_ok();\nif !pid_ok {\n    // use $SHELL fallback instead of Shell::current()\n}","typeGuard":null,"tryCatchPattern":"// Rust\nlet shell = std::panic::catch_unwind(Shell::current)\n    .ok()\n    .or_else(|| std::env::var(\"SHELL\").ok().map(|s| Shell::from_string(&s)));","preventionTips":["Retry on transient failures — snapshot races are usually one-shot.","Ensure /proc visibility in containers running atuin hooks.","Fall back to $SHELL when live process detection fails.","Keep sysinfo updated for platform enumeration fixes."],"tags":["process","panic","sysinfo","race-condition"],"backgroundTag":"resource-not-found","analyzedSha":"c0c717ab04c881764bcad4b3d169a507e2432643","analyzedAt":"2026-09-12T07:40:01.341Z","contentChangedAt":"2026-09-12T07:40:01.341Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}