Made sure that port 9090 could not be randomly selected.

This commit is contained in:
Jeff Baskin 2022-06-12 09:07:06 -04:00
parent e40e190e1e
commit e79cf82b62
1 changed files with 6 additions and 5 deletions

View File

@ -30,7 +30,7 @@ class Server:
@property @property
def port(self): def port(self):
"""Get the port of the server.""" """Get the port of the server."""
port = 9090 port = "9090"
if "MTT_PORT" in self.env: if "MTT_PORT" in self.env:
port = self.env["MTT_PORT"] port = self.env["MTT_PORT"]
return port return port
@ -68,7 +68,8 @@ class Server:
def set_safe_port(self): def set_safe_port(self):
"""Set the server port to something not being used.""" """Set the server port to something not being used."""
sock = socket() while self.port == "9090":
sock.bind((self.address, 0)) sock = socket()
self.port = sock.getsockname()[1] sock.bind((self.address, 0))
sock.close() self.port = sock.getsockname()[1]
sock.close()