diff --git a/server.py b/server.py index ad00b272..91e4561a 100644 --- a/server.py +++ b/server.py @@ -63,6 +63,12 @@ def _fd_to_socket(fd: int) -> socket.socket: # ``family``, ``type`` and ``proto`` attributes. 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) + # aiohttp’s SockSite registers the socket with the event loop, which # requires a non‑blocking descriptor. sock.setblocking(False)