diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py index 1eaf453d5..646d684ef 100644 --- a/gunicorn/arbiter.py +++ b/gunicorn/arbiter.py @@ -9,6 +9,7 @@ import sys import time import traceback +import socket from gunicorn.errors import HaltServer, AppImportError from gunicorn.pidfile import Pidfile @@ -151,7 +152,8 @@ def start(self): for fd in os.environ.pop('GUNICORN_FD').split(','): fds.append(int(fd)) - self.LISTENERS = sock.create_sockets(self.cfg, self.log, fds) + if not (self.cfg.reuse_port and hasattr(socket, 'SO_REUSEPORT')): + self.LISTENERS = sock.create_sockets(self.cfg, self.log, fds) listeners_str = ",".join([str(lnr) for lnr in self.LISTENERS]) self.log.debug("Arbiter booted") @@ -604,6 +606,8 @@ def spawn_worker(self): try: util._setproctitle("worker [%s]" % self.proc_name) self.log.info("Booting worker with pid: %s", worker.pid) + if self.cfg.reuse_port: + worker.sockets = sock.create_sockets(self.cfg, self.log) self.cfg.post_fork(self, worker) worker.init_process() sys.exit(0) diff --git a/gunicorn/workers/ggevent.py b/gunicorn/workers/ggevent.py index b9b9b4408..4bcfecb49 100644 --- a/gunicorn/workers/ggevent.py +++ b/gunicorn/workers/ggevent.py @@ -41,7 +41,7 @@ def patch(self): sockets = [] for s in self.sockets: sockets.append(socket.socket(s.FAMILY, socket.SOCK_STREAM, - fileno=s.sock.fileno())) + fileno=s.sock.detach())) self.sockets = sockets def notify(self):