Skip to content

Commit

Permalink
fix: 🐛 gunicorn load balance requests between workers
Browse files Browse the repository at this point in the history
  • Loading branch information
bashirmindee committed Aug 21, 2024
1 parent 79fdef0 commit f5e30e1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gunicorn/arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys
import time
import traceback
import socket

from gunicorn.errors import HaltServer, AppImportError
from gunicorn.pidfile import Pidfile
Expand Down Expand Up @@ -152,7 +153,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")
Expand Down Expand Up @@ -605,6 +607,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)
Expand Down

0 comments on commit f5e30e1

Please sign in to comment.