From 2fc323704557191eacbef435f78d7014a74d8587 Mon Sep 17 00:00:00 2001 From: Allen Date: Tue, 20 Oct 2020 19:19:50 -0700 Subject: [PATCH] [Dashboard] Update dashboard port checking so that we can instantly reuse the dashboard port (#11487) Co-authored-by: Allen Yin --- python/ray/_private/services.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/ray/_private/services.py b/python/ray/_private/services.py index 10b9803de..60c8e8885 100644 --- a/python/ray/_private/services.py +++ b/python/ray/_private/services.py @@ -1019,10 +1019,11 @@ def start_dashboard(require_dashboard, Returns: ProcessInfo for the process that was started. """ + port_test_socket = socket.socket() + port_test_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) if port == ray_constants.DEFAULT_DASHBOARD_PORT: while True: try: - port_test_socket = socket.socket() port_test_socket.bind(("127.0.0.1", port)) port_test_socket.close() break @@ -1030,7 +1031,6 @@ def start_dashboard(require_dashboard, port += 1 else: try: - port_test_socket = socket.socket() port_test_socket.bind(("127.0.0.1", port)) port_test_socket.close() except socket.error: