工作进程报错

@param  \Swoole\Server   $server
@param  int              $workerId
@param  int              $workerPid
@param  int              $exitCode
511912
public function onWorkerError(SwServer $server, int $workerId, int $workerPid, int $exitCode)
    {
        $workerType = $server->taskworker ? 'task' : 'worker';

        // {{ log
        $this->get('logger')->info('Worker 进程异常退出', [
            'id' => $workerId,
            'pid' => $workerPid,
            'type' => ucfirst($workerType),
            'exitcode' => $exitCode,
        ]);
        // }}

        unset($workerType);

        $this->callProtocolMethod('onError', $server, $workerId);
    }
63012
public function createWriterWithProject($writerId, $pid, $username, $password, $params = [])
    {
        $job = $this->createWriterWithProjectAsync($writerId, $pid, $username, $password, $params);
        if (!isset($job['url'])) {
            throw new ServerException('Create writer job returned unexpected result: ' . json_encode($job, JSON_PRETTY_PRINT));
        }

        return $this->waitForJob($job['url']);
    }
1006234
public static function postWait(TaskInfo $taskInfo, $timeout, $workerID = -1)
    {
        $server = ServerManage::getServer('main')->getSwooleServer();
        $result = $server->taskwait($taskInfo, $timeout, $workerID);
        call_user_func([$taskInfo->getTaskHandler(), 'finish'], $server, -1, $result);
        return $result;
    }
92380
function opcodeSwitch($client_id, &$ws)
    {
        $this->log("[$client_id] opcode={$ws['opcode']}");

        switch($ws['opcode'])
        {
            //data frame
            case self::OPCODE_BINARY_FRAME:
            case self::OPCODE_TEXT_FRAME:
                if (0x1 === $ws['fin'])
                {
                    $this->onMessage($client_id, $ws);
                }
                else
                {
                    $this->log("not finish frame");
                }
                break;

            //heartbeat
            case self::OPCODE_PING:
                $message = &$ws['message'];
                if (0x0  === $ws['fin'] or 0x7d  <  $ws['length'])
                {
                    $this->close($client_id, self::CLOSE_PROTOCOL_ERROR, "ping error");
                    break;
                }
                $this->connections[$client_id]['time'] = time();
                $this->send($client_id, $message, self::OPCODE_PONG, true);
                break;

            case self::OPCODE_PONG:
                if (0 === $ws['fin'])
                {
                    $this->close($client_id, self::CLOSE_PROTOCOL_ERROR, "pong? server cannot pong.");
                }
                break;

            //close the connection
            case self::OPCODE_CONNECTION_CLOSE:
                $length = &$ws['length'];
                if (1 === $length or 0x7d < $length)
                {
                    $this->close($client_id, self::CLOSE_PROTOCOL_ERROR, "client active close");
                    break;
                }

                if ($length > 0)
                {
                    $message = $ws['message'];
                    $_code   = unpack('nc', substr($message, 0, 2));
                    $code    = $_code['c'];

                    if ($length > 2)
                    {
                        $reason = substr($message, 2);
                        if (false === (bool) preg_match('//u', $reason))
                        {
                            $this->close($client_id, self::CLOSE_MESSAGE_ERROR);
                            break;
                        }
                    }

                    if (1000 > $code || (1004 <= $code && $code <= 1006) || (1012 <= $code && $code <= 1016) || 5000  <= $code)
                    {
                        $this->close($client_id, self::CLOSE_PROTOCOL_ERROR);
                        break;
                    }
                    else
                    {
                        $this->close($client_id, self::CLOSE_PROTOCOL_ERROR, "client active close, code={$code}");
                        break;
                    }
                }
                break;
            default:
                $this->close($client_id, self::CLOSE_PROTOCOL_ERROR, "unkown websocket opcode[{$ws['opcode']}]");
                break;
        }
        unset($this->frame_list[$client_id]);
    }
1127700
public function onPipeMessage(Server $server, int $srcWorkerId, string $message)
    {
        /* @var PipeMessageInterface $pipeMessage */
        $pipeMessage = App::getBean(PipeMessage::class);
        list($type, $data) = $pipeMessage->unpack($message);

        App::trigger(AppEvent::PIPE_MESSAGE, null, $type, $data, $srcWorkerId);
    }
955009
public function restartWorker($serverId, $siteId, $workerId, $wait = true)
    {
        $this->post("servers/$serverId/sites/$siteId/workers/$workerId/restart");

        if ($wait) {
            $this->retry(30, function () use ($serverId, $siteId, $workerId) {
                $key = $this->worker($serverId, $siteId, $workerId);

                return $key->status == 'installed';
            });
        }
    }
1168440
public function onOpen($server, $req)
    {
        $request = $this->prepareRequest($req);
        /** @var Websocket $websocket */
        $websocket = $this->app->make(Websocket::class);
        /** @var Sandbox $sandbox */
        $sandbox = $this->app->make(Sandbox::class);

        try {
            $websocket->reset(true)->setSender($req->fd);
            // set current request to sandbox
            $sandbox->setRequest($request);
            // enable sandbox
            $sandbox->init();

            // check if socket.io connection established
            if (!$this->websocketHandler->onOpen($req->fd, $request)) {
                return;
            }

            // trigger 'connect' websocket event
            if ($websocket->eventExists('connect')) {
                $websocket->call('connect', $request);
            }
        } catch (Throwable $e) {
            $this->logServerError($e);
        } finally {
            // disable and recycle sandbox resource
            $sandbox->clear();
        }
    }
243137
protected function onJobCompleted(string $workerId, string $jobId, string $result = '')
    {
        $jobType = $this->jobTypes[$jobId];
        $clientAddress = $this->jobAddresses[$jobId];
        if ($jobType === 'normal') {
            $this->respondToClient($clientAddress, $result);
        }
        unset(
            $this->jobTypes[$jobId],
            $this->jobAddresses[$jobId],
            $this->workerJobMap[$workerId]
        );
    }
482487
public function setExitCode($exitCode)
    {
        $this->exitCode = (int) $exitCode;

        $r = new \ReflectionProperty($this->error, 'code');
        $r->setAccessible(true);
        $r->setValue($this->error, $this->exitCode);
    }
160239
public function endCommand(CommandInterface $command, $exitCode, $store = null)
    {
        if ($this->output->isVeryVerbose()) {
            $this->newLine();
        }

        if ($this->output->isVerbose()) {
            $this->writeln($this->getVerboseCommandEndMessage($command, $exitCode));
            $this->newLine();

            return;
        }

        $this->endCommandOutputIfNormalOutput($command, $store);
    }
704098
protected function runWorker($id, $pid)
    {
        $this->isWorker = true;
        $this->isMaster = false;

        $this->id = $id;
        $this->masterPid = $this->pid;
        $this->pid = getmypid();

        $eCode = $this->receiveTasks($this->queue);

        $this->log("Worker #$id exited(Exit-Code:$eCode)", ProcessLogger::PROC_INFO);
        $this->quit($eCode);
    }
1029719
public function dispatchWorkerStart(int $workerId)
    {
        $this->settings["workerId"] = $workerId;

        $loadProcessor = new LoadProcessor($this->container);
        $loadProcessor->load($this->settings);

        $this->collectMiddleware();

        foreach ($this->workerMiddleware as $middleware) {
            $middleware->__invoke($this->settings);
        }
    }
234765
public function onOpen($server, $swooleRequest)
    {
        $illuminateRequest = Request::make($swooleRequest)->toIlluminate();
        $websocket = $this->app->make(Websocket::class);
        $sandbox = $this->app->make(Sandbox::class);

        try {
            $websocket->reset(true)->setSender($swooleRequest->fd);
            // set currnt request to sandbox
            $sandbox->setRequest($illuminateRequest);
            // enable sandbox
            $sandbox->enable();
            // check if socket.io connection established
            if (! $this->websocketHandler->onOpen($swooleRequest->fd, $illuminateRequest)) {
                return;
            }
            // trigger 'connect' websocket event
            if ($websocket->eventExists('connect')) {
                // set sandbox container to websocket pipeline
                $websocket->setContainer($sandbox->getApplication());
                $websocket->call('connect', $illuminateRequest);
            }
        } catch (Throwable $e) {
            $this->logServerError($e);
        } finally {
            // disable and recycle sandbox resource
            $sandbox->disable();
        }
    }
287992
public function onWorkerStop(SwServer $server, int $workerId)
    {
        $workerType = $server->taskworker ? 'task' : 'worker';

        // {{ log
        $this->get('logger')->info('结束 Worker 进程', [
            'id' => $workerId,
            'type' => ucfirst($workerType)
        ]);
        // }}

        if ($workerType === 'worker') {
            $this->shutdownWorkerStartItems();
            $this->callProtocolMethod('onStop', $server, $workerId);
        }

        unset($workerType);
    }
70903
public static function create($name, $workerNum = null, $args = [], $ipcType = 0, $msgQueueKey = null): \Swoole\Process\Pool
    {
        $processPoolOption = ProcessPoolParser::getInstance()->getProcessPool($name);
        if(null === $processPoolOption)
        {
            return null;
        }
        if(null === $workerNum)
        {
            $workerNum = $processPoolOption['ProcessPool']->workerNum;
        }
        if(null === $ipcType)
        {
            $ipcType = $processPoolOption['ProcessPool']->ipcType;
        }
        if(null === $msgQueueKey)
        {
            $msgQueueKey = $processPoolOption['ProcessPool']->msgQueueKey;
        }
        
        $pool = new \Swoole\Process\Pool($workerNum, $ipcType, $msgQueueKey);

        $pool->on('WorkerStart', function ($pool, $workerId) use($name, $workerNum, $args, $ipcType, $msgQueueKey, $processPoolOption) {
            Imi::setProcessName('processPool', [
                'processPoolName'   =>  $name,
                'workerId'          =>  $workerId,
            ]);
            // 随机数播种
            mt_srand();
            $processInstance = BeanFactory::newInstance($processPoolOption['className'], $args);
            // 加载服务器注解
            \Imi\Bean\Annotation::getInstance()->init(\Imi\Main\Helper::getAppMains());
            App::initWorker();
            // 进程开始事件
            Event::trigger('IMI.PROCESS_POOL.PROCESS.BEGIN', [
                'name'          => $name,
                'pool'          => $pool,
                'workerId'      => $workerId,
                'workerNum'     => $workerNum,
                'args'          => $args,
                'ipcType'       => $ipcType,
                'msgQueueKey'   => $msgQueueKey,
            ]);
            // 执行任务
            call_user_func([$processInstance, 'run'], $pool, $workerId, $name, $workerNum, $args, $ipcType, $msgQueueKey);
            swoole_event_wait();
        });
        
        $pool->on('WorkerStop', function ($pool, $workerId) use($name, $workerNum, $args, $ipcType, $msgQueueKey) {
            // 进程结束事件
            Event::trigger('IMI.PROCESS_POOL.PROCESS.END', [
                'name'          => $name,
                'pool'          => $pool,
                'workerId'      => $workerId,
                'workerNum'     => $workerNum,
                'args'          => $args,
                'ipcType'       => $ipcType,
                'msgQueueKey'   => $msgQueueKey,
            ]);
        });
        
        return $pool;

    }
945933
protected function reportWorkerError($workerId, $workerPid, $exitCode, $signal)
    {
        $this->handleException(new WorkerExitUnexpectedException(sprintf(
            'The worker %d quit unexpected with exit code %d, signal %d, pid %d.',
            $workerId, $exitCode, $signal, $workerPid
        )));
    }
1155756
public function isUserProcess($worker_id = null)
    {
        //一定要===
        if ($worker_id === null) {
            $worker_id = $this->workerId;
        }
        return $worker_id >= $this->worker_num + $this->task_num ? true : false;
    }