diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py index cd838d00..a007f9ef 100644 --- a/gunicorn/arbiter.py +++ b/gunicorn/arbiter.py @@ -686,11 +686,18 @@ class Arbiter: self.app, self.timeout / 2.0, self.cfg, self.log) self.cfg.pre_fork(self, worker) + + # Stop control server before fork to prevent deadlocks. + # The asyncio thread holds locks that would be stuck in the child. + self._stop_control_server() + pid = os.fork() if pid != 0: worker.pid = pid self.WORKERS[pid] = worker self._stats['workers_spawned'] += 1 + # Restart control server in parent after fork + self._start_control_server() return pid # Do not inherit the temporary files of other workers diff --git a/gunicorn/config.py b/gunicorn/config.py index fa399f03..9fc4603b 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -3123,7 +3123,7 @@ class ControlSocket(Setting): cli = ["--control-socket"] meta = "PATH" validator = validate_string - default = "gunicorn.ctl" + default = "/tmp/gunicorn.ctl" desc = """\ Unix socket path for control interface. @@ -3131,8 +3131,8 @@ class ControlSocket(Setting): ``gunicornc`` command-line tool. Commands include viewing worker status, adjusting worker count, and graceful reload/shutdown. - By default, creates ``gunicorn.ctl`` in the working directory. - Set an absolute path for a fixed location (e.g., ``/var/run/gunicorn.ctl``). + By default, creates ``/tmp/gunicorn.ctl``. Set an absolute path for a + different location (e.g., ``/var/run/gunicorn.ctl``). Use ``--no-control-socket`` to disable.