Select stream port from predefined range (#290)
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Sun, 8 May 2022 09:02:57 +0000 (11:02 +0200)
committerGitHub <noreply@github.com>
Sun, 8 May 2022 09:02:57 +0000 (11:02 +0200)
music_assistant/helpers/util.py

index e121d40ee4af7f5b9acc2f5e399c0a8d89167de8..2060de83715a0bfb4e68401e802869f6a5bfc279 100755 (executable)
@@ -5,7 +5,6 @@ import asyncio
 import os
 import platform
 import socket
-import socketserver
 import tempfile
 from typing import Any, Callable, Dict, List, Optional, Set, Tuple, TypeVar
 
@@ -182,11 +181,10 @@ def is_port_in_use(port: int) -> bool:
 
 
 def select_stream_port() -> int:
-    """Automaticlaly find available stream port, prefer the default 8095."""
-    if not is_port_in_use(8095):
-        return 8095
-    with socketserver.TCPServer(("localhost", 0), None) as _sock:
-        return _sock.server_address[1]
+    """Automatically find available stream port, prefer the default 8095."""
+    for port in range(8095, 8195):
+        if not is_port_in_use(port):
+            return port
 
 
 def get_folder_size(folderpath):