Skip to content

Commit

Permalink
Catch errors setting SO_REUSEPORT
Browse files Browse the repository at this point in the history
Fix #1480
  • Loading branch information
tilgovi committed Mar 14, 2017
1 parent 2de1ea3 commit 9e076f4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions gunicorn/sock.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ def __getattr__(self, name):

def set_options(self, sock, bound=False):
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
if hasattr(socket, 'SO_REUSEPORT'):
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
if hasattr(socket, 'SO_REUSEPORT'): # pragma: no cover
try:
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
except socket.error as err:
if err[0] in (errno.ENOPROTOOPT, errno.EINVAL):
pass
else:
raise
if not bound:
self.bind(sock)
sock.setblocking(0)
Expand Down

0 comments on commit 9e076f4

Please sign in to comment.