Skip to content

Commit 0a0ef9d

Browse files
author
Ankit Patel
committed
only create sockets in forked processes not in master
1 parent 792edf6 commit 0a0ef9d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

gunicorn/arbiter.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import sys
1111
import time
1212
import traceback
13+
import socket
1314

1415
from gunicorn.errors import HaltServer, AppImportError
1516
from gunicorn.pidfile import Pidfile
@@ -152,7 +153,8 @@ def start(self):
152153
for fd in os.environ.pop('GUNICORN_FD').split(','):
153154
fds.append(int(fd))
154155

155-
self.LISTENERS = sock.create_sockets(self.cfg, self.log, fds)
156+
if not (self.cfg.reuse_port and hasattr(socket, 'SO_REUSEPORT')):
157+
self.LISTENERS = sock.create_sockets(self.cfg, self.log, fds)
156158

157159
listeners_str = ",".join([str(lnr) for lnr in self.LISTENERS])
158160
self.log.debug("Arbiter booted")
@@ -579,6 +581,8 @@ def spawn_worker(self):
579581
try:
580582
util._setproctitle("worker [%s]" % self.proc_name)
581583
self.log.info("Booting worker with pid: %s", worker.pid)
584+
if self.cfg.reuse_port:
585+
worker.sockets = sock.create_sockets(self.cfg, self.log)
582586
self.cfg.post_fork(self, worker)
583587
worker.init_process()
584588
sys.exit(0)

0 commit comments

Comments
 (0)