Allow reuse of socket (works without SELinux, probably no longer needed with proper workaround)

This commit is contained in:
2025-12-03 23:00:05 +01:00
parent c9d4b636e6
commit 943105ccef

View File

@@ -63,6 +63,12 @@ def _fd_to_socket(fd: int) -> socket.socket:
# ``family``, ``type`` and ``proto`` attributes. # ``family``, ``type`` and ``proto`` attributes.
sock = socket.socket(fileno=fd) sock = socket.socket(fileno=fd)
# Allow aiohttp to call listen() again without EPERM.
# On many Linux kernels the flag must be set *before* the first listen(),
# but systemd binds the socket without it. Setting it now is sufficient
# for the second listen() performed by aiohttp.
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
# aiohttps SockSite registers the socket with the event loop, which # aiohttps SockSite registers the socket with the event loop, which
# requires a nonblocking descriptor. # requires a nonblocking descriptor.
sock.setblocking(False) sock.setblocking(False)