{"record":{"id":"5599e1adc9aa8ced","repo":"walkor/workerman","slug":"setsid-fail","errorCode":null,"errorMessage":"Setsid fail","messagePattern":"Setsid fail","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"src/Worker.php","lineNumber":1443,"sourceCode":"    }\n\n    /**\n     * Run as daemon mode.\n     */\n    protected static function daemonize(): void\n    {\n        if (!static::$daemonize || DIRECTORY_SEPARATOR !== '/') {\n            return;\n        }\n        umask(0);\n        $pid = pcntl_fork();\n        if (-1 === $pid) {\n            throw new RuntimeException('Fork fail');\n        } elseif ($pid > 0) {\n            exit(0);\n        }\n        if (-1 === posix_setsid()) {\n            throw new RuntimeException(\"Setsid fail\");\n        }\n        // Fork again avoid SVR4 system regain the control of terminal.\n        $pid = pcntl_fork();\n        if (-1 === $pid) {\n            throw new RuntimeException(\"Fork fail\");\n        } elseif (0 !== $pid) {\n            exit(0);\n        }\n    }\n\n    /**\n     * Redirect standard output to stdoutFile.\n     *\n     * @return void\n     */\n    public static function resetStd(): void\n    {\n        if (!static::$daemonize || DIRECTORY_SEPARATOR !== '/') {","sourceCodeStart":1425,"sourceCodeEnd":1461,"githubUrl":"https://github.com/walkor/workerman/blob/1391112a61d23020e11e7b89f17050f6cfaea431/src/Worker.php#L1425-L1461","documentation":"After the first daemonize fork, Workerman calls posix_setsid() to start a new session and release the controlling terminal. It returns -1 when the caller is already a process-group leader or when the environment (seccomp profiles, some container/sandbox configurations) disallows setsid. In the normal daemonize flow the fresh child is never a leader, so this error points at an environment restriction or an unconventional daemonize invocation.","triggerScenarios":"Starting with -d inside containers/sandboxes whose seccomp policy blocks setsid; invoking Workerman's daemonize path when the process already leads a session (double-daemonize, unusual supervisors); nested process managers re-forking the master.","commonSituations":"Hardened Docker/gVisor/Kata sandbox profiles; running under custom supervisors that already detached the process then call Workerman with -d again.","solutions":["Run Workerman in foreground mode (drop -d) and let the supervisor (systemd, docker, supervisord) handle daemonization","Loosen the seccomp/sandbox profile to allow setsid, or run in a standard container runtime","Avoid double-detaching: if the parent environment already daemonizes the process, do not pass -d to Workerman"],"exampleFix":"# before\nphp start.php start -d   # inside sandbox blocking setsid -> 'Setsid fail'\n\n# after\n# let systemd/docker detach instead\nphp start.php start        # foreground, supervised by the init system","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer foreground Workerman under systemd/docker and drop -d in sandboxed environments","Do not daemonize a process that a supervisor already detached"],"tags":["php","workerman","daemonize","posix","setsid","containers"],"backgroundTag":"setsid-failed","analyzedSha":"1391112a61d23020e11e7b89f17050f6cfaea431","analyzedAt":"2026-08-21T02:05:46.744Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}