From 2d8c4f42d4137490c614edb0e168a6f383db2ed5 Mon Sep 17 00:00:00 2001 From: varunbajpai Date: Sat, 8 Jun 2024 00:25:11 +0530 Subject: [PATCH] updated mr to include latest feautures with load balanced sockets --- gunicorn/arbiter.py | 7 +++++-- gunicorn/workers/ggevent.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py index 1cf436748..06db6f509 100644 --- a/gunicorn/arbiter.py +++ b/gunicorn/arbiter.py @@ -10,6 +10,7 @@ import sys import time import traceback +import socket from gunicorn.errors import HaltServer, AppImportError from gunicorn.pidfile import Pidfile @@ -151,8 +152,8 @@ def start(self): fds = [] 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") @@ -605,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 2125a32d0..39f661b91 100644 --- a/gunicorn/workers/ggevent.py +++ b/gunicorn/workers/ggevent.py @@ -42,7 +42,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):