Skip to content

Commit

Permalink
Work/fix firewall for localhost (#8868)
Browse files Browse the repository at this point in the history
Co-authored-by: Hendrik Makait <hendrik@makait.com>
  • Loading branch information
maldag and hendrikmakait committed Sep 12, 2024
1 parent b28822b commit ec3f4ec
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions distributed/deploy/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class LocalCluster(SpecCluster):
'localhost:8787' or '0.0.0.0:8787'. Defaults to ':8787'.
Set to ``None`` to disable the dashboard.
Use ':0' for a random port.
When specifying only a port like ':8787', the dashboard will bind to the given interface from the ``host`` parameter.
If ``host`` is empty, binding will occur on all interfaces '0.0.0.0'.
To avoid firewall issues when deploying locally, set ``host`` to 'localhost'.
worker_dashboard_address: str
Address on which to listen for the Bokeh worker diagnostics server like
'localhost:8787' or '0.0.0.0:8787'. Defaults to None which disables the dashboard.
Expand Down
9 changes: 7 additions & 2 deletions distributed/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,14 @@ def start_http_server(
self.http_server = HTTPServer(self.http_application, ssl_options=ssl_options)

http_addresses = clean_dashboard_address(dashboard_address or default_port)

for http_address in http_addresses:
if http_address["address"] is None:
# Handle default case for dashboard address
# In case dashboard_address is given, e.g. ":8787"
# the address is empty and it is intended to listen to all interfaces
if dashboard_address is not None and http_address["address"] == "":
http_address["address"] = "0.0.0.0"

if http_address["address"] is None or http_address["address"] == "":
address = self._start_address
if isinstance(address, (list, tuple)):
address = address[0]
Expand Down
2 changes: 1 addition & 1 deletion distributed/tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1969,7 +1969,7 @@ async def test_scheduler_file():
@pytest.mark.parametrize(
"dashboard_address,expect",
[
(None, ("::", "0.0.0.0")),
(None, ("::", "0.0.0.0", "127.0.0.1")),
("127.0.0.1:0", ("127.0.0.1",)),
],
)
Expand Down
2 changes: 1 addition & 1 deletion distributed/tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ async def test_service_hosts_match_worker(s):

async with Worker(s.address, host="tcp://127.0.0.1") as w:
sock = first(w.http_server._sockets.values())
assert sock.getsockname()[0] in ("::", "0.0.0.0")
assert sock.getsockname()[0] in ("::", "127.0.0.1")

# See what happens with e.g. `dask worker --listen-address tcp://:8811`
async with Worker(s.address, host="") as w:
Expand Down

0 comments on commit ec3f4ec

Please sign in to comment.