{"id":"34c98d23a9dd15bf","repo":"laravel/framework","slug":"concurrent-process-failed-with-exit-code-result","errorCode":null,"errorMessage":"Concurrent process failed with exit code [$result->exitCode()]. Message: $result->errorOutput()","messagePattern":"Concurrent process failed with exit code \\[\\$result->exitCode\\(\\)\\]\\. Message: \\$result->errorOutput\\(\\)","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/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Concurrency/ProcessDriver.php#L35-L71","documentation":"Thrown by ProcessDriver::run() when any process in the pool exits with a failure status. The process driver serializes closures and runs them via the artisan invoke-serialized-closure command in a pool; if a child process crashes (non-zero exit code), the driver collects errorOutput() and rethrows as an Exception with the exit code and stderr.","triggerScenarios":"Passing a closure that throws an exception, fatals, runs out of memory, or references unserializable/non-existent symbols. Also environment issues: missing artisan binary, wrong working directory, deserialization mismatch between parent and child PHP environments.","commonSituations":"Closure capturing an unserializable object. PHP version/extension mismatch between the dispatching process and the spawned workers. A closure that hits a fatal error (class not found, permission denied) inside the child.","solutions":["Inspect the embedded errorOutput() in the message for the child's stderr/stack trace.","Run the same closure synchronously (sync driver) to reproduce the underlying error.","Ensure closures only capture serializable values and the artisan bootstrap is identical for workers."],"exampleFix":"// before\n$concurrency->run([\n    fn () => $heavyService->process($job), // throws in child\n]);\n\n// after\n$concurrency->driver('sync')->run([\n    fn () => $heavyService->process($job), // reproduce locally first\n]);","handlingStrategy":"fallback","validationCode":"// reproduce synchronously first to validate the closure\ntry {\n    app(\\Illuminate\\Concurrency\\ConcurrencyManager::class)->driver('sync')->run($tasks);\n} catch (\\Throwable $e) {\n    throw new \\RuntimeException('Task fails in sync mode: '.$e->getMessage(), 0, $e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    $results = $concurrency->run($tasks);\n} catch (\\Exception $e) {\n    // $e->getMessage() contains child exit code + errorOutput()\n    $results = $concurrency->driver('sync')->run($tasks);\n}","preventionTips":["Validate closures in sync mode before running them concurrently.","Only capture serializable values in closures (avoid PDO statements, open resources, service singletons).","Keep the PHP version and extensions identical between dispatcher and worker processes."],"tags":["laravel","concurrency","process-pool","child-process","deserialization"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}