{"record":{"id":"708287dd73af6f2e","repo":"laravel/framework","slug":"concurrent-process-failed-with-exit-code-s-mes","errorCode":null,"errorMessage":"Concurrent process failed with exit code [%s]. Message: %s","messagePattern":"Concurrent process failed with exit code \\[(.+?)\\]\\. Message: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Concurrency/ProcessDriver.php","lineNumber":53,"sourceCode":"        $command = Application::formatCommandString('invoke-serialized-closure');\n\n        $results = $this->processFactory->pool(function (Pool $pool) use ($tasks, $command, $timeout) {\n            foreach (Arr::wrap($tasks) as $key => $task) {\n                $process = $pool->as($key)->path(base_path())->env([\n                    'LARAVEL_INVOKABLE_CLOSURE' => base64_encode(\n                        serialize(new SerializableClosure($task))\n                    ),\n                ])->command($command);\n\n                if (! is_null($timeout)) {\n                    $process->timeout($timeout);\n                }\n            }\n        })->start()->wait();\n\n        return $results->collect()->mapWithKeys(function ($result, $key) {\n            if ($result->failed()) {\n                throw new Exception('Concurrent process failed with exit code ['.$result->exitCode().']. Message: '.$result->errorOutput());\n            }\n\n            $output = $result->output();\n\n            if (($pos = strpos($output, \"\\x1f\\x8b\")) !== false) {\n                $output = substr($output, 0, $pos);\n            }\n\n            $result = json_decode($output, true);\n\n            if (! $result['successful']) {\n                throw new $result['exception'](\n                    ...(! empty(array_filter($result['parameters'], fn ($parameter) => ! is_null($parameter)))\n                        ? $result['parameters']\n                        : [$result['message']])\n                );\n            }\n","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Concurrency/ProcessDriver.php#L35-L71","documentation":"Thrown by ProcessDriver::run() when a concurrent subprocess in the pool exits with a failure ($result->failed()). The driver spawns child PHP processes (via the invoke-serialized-closure command) to run each task; if any child crashes or returns a non-zero exit code, its exitCode and errorOutput are wrapped in an Exception. The message includes the exit code and the child's stderr/stderr captured output.","triggerScenarios":"Passing a closure to Concurrency::run([...]) (process driver) where one closure throws, references an undefined symbol, or the child PHP process is killed (OOM, signal, timeout).","commonSituations":"A task closure throws an uncaught exception; the serialized closure captures an unserializable object; child process exceeds the timeout and is killed; missing env/bootstrap so the invoke-serialized-closure command fails; out-of-memory kills.","solutions":["Inspect the child's errorOutput in the exception message for the underlying cause (it usually contains the real stack trace).","Add try/catch inside each task closure so failures are contained and reported via the result, not the process exit.","Ensure closures only capture serializable values and that the app bootstraps in the child (correct base_path, env).","Increase the timeout if the task is being killed mid-run."],"exampleFix":"// before\n$results = Concurrency::run([\n    fn () => riskyOperation($input),\n]);\n// after\n$results = Concurrency::run([\n    function () use ($input) {\n        try { return riskyOperation($input); }\n        catch (\\Throwable $e) { return ['error' => $e->getMessage()]; }\n    },\n]);","handlingStrategy":"try-catch","validationCode":"// Pre-validate that closures capture only serializable values\n$reflect = new \\ReflectionFunction($task);\nforeach ($reflect->getStaticVariables() as $v) {\n    try { serialize($v); } catch (\\Throwable $e) {\n        throw new \\InvalidArgumentException('Task captures unserializable value');\n    }\n}","typeGuard":"function isSerializableClosure(\\Closure $c): bool {\n    try { serialize(new \\Laravel\\SerializableClosure\\SerializableClosure($c)); return true; }\n    catch (\\Throwable $e) { return false; }\n}","tryCatchPattern":"try {\n    $results = Concurrency::run($tasks);\n} catch (\\Exception $e) {\n    // $e->getMessage() contains the child exit code and errorOutput\n    logger()->error('Concurrency failed: '.$e->getMessage());\n    $results = array_map(fn ($t) => $t(), $tasks); // fallback to sync\n}","preventionTips":["Wrap each task body in try/catch so failures return a result, not a crash.","Capture only serializable values; avoid PDO/resources/singletons in closures.","Set an explicit timeout sized to the slowest task.","Log errorOutput from the exception to diagnose the child cause."],"tags":["concurrency","process","subprocess","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}