From abdb5cb531c0a2a6f376c34e1e1449fd4fb8bb1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=2E=20K=C3=A4rkk=C3=A4inen?= Date: Tue, 5 Sep 2023 19:28:46 +0100 Subject: [PATCH] Better diagnostic for permission denied on bind() for low ports. --- sanic/server/socket.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sanic/server/socket.py b/sanic/server/socket.py index a77e80a0..755e39c5 100644 --- a/sanic/server/socket.py +++ b/sanic/server/socket.py @@ -112,6 +112,16 @@ def configure_socket( server_settings["port"], backlog=backlog, ) + except PermissionError as e: + p = server_settings["port"] + if p and server_settings["port"] < 1024: + addr = f"{server_settings['host']}:{p}" + e = ServerError( + f"Permission denied binding to {addr}.\n\n" + "Use `sudo sanic` to run on a privileged port.\n" + ) + e.quiet = True + raise e from None except OSError as e: # no cov error = ServerError( f"Sanic server could not start: {e}.\n\n"