# Buggy code
def __init__(self, http_host, http_port, redis_address, redis_password, log_dir):
    # NodeInfoGcsService
    self._gcs_node_info_stub = None
    self._gcs_rpc_error_counter = 0
    # Public attributes are accessible for all head modules.
    self.http_host = http_host
    self.http_port = http_port
    self.redis_address = dashboard_utils.address_tuple(redis_address)
    self.redis_password = redis_password
    self.log_dir = log_dir
    self.aioredis_client = None
    self.aiogrpc_gcs_channel = None
    self.http_session = None
    self.ip = ray._private.services.get_node_ip_address()
    self.server = aiogrpc.server(options=(("grpc.so_reuseport", 0),))
    self.grpc_port = self.server.add_insecure_port("[::]:0")
    logger.info("Dashboard head grpc address: %s:%s", self.ip, self.grpc_port)
    logger.info("Dashboard head http address: %s:%s", self.http_host, self.http_port)


# Traceback (OSError)
2021-01-07 03:57:35,395	WARNING worker.py:1044 -- The dashboard on node travis-job-a2c3f054-a588-45a5-b10a-2456ba486c28 failed with the following error:
Traceback (most recent call last):
File "/opt/miniconda/lib/python3.6/asyncio/base_events.py", line 1073, in create_server
sock.bind(sa)
OSError: [Errno 98] Address already in use
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/travis/build/ray-project/ray/python/ray/new_dashboard/dashboard.py", line 197, in <module>
loop.run_until_complete(dashboard.run())
File "/opt/miniconda/lib/python3.6/asyncio/base_events.py", line 488, in run_until_complete
return future.result()
File "/home/travis/build/ray-project/ray/python/ray/new_dashboard/dashboard.py", line 100, in run
await self.dashboard_head.run()
File "/home/travis/build/ray-project/ray/python/ray/new_dashboard/head.py", line 220, in run
*(m.run(self.server) for m in modules))
File "/opt/miniconda/lib/python3.6/site-packages/aiohttp/web.py", line 369, in _run_app
await site.start()
File "/opt/miniconda/lib/python3.6/site-packages/aiohttp/web_runner.py", line 103, in start
reuse_port=self._reuse_port)
File "/opt/miniconda/lib/python3.6/asyncio/base_events.py", line 1077, in create_server
% (sa, err.strerror.lower()))
OSError: [Errno 98] error while attempting to bind on address ('127.0.0.1', 8265): address already in use

# Fixed code
def __init__(
    self,
    http_host,
    http_port,
    http_port_retries,
    redis_address,
    redis_password,
    log_dir,
):
    # NodeInfoGcsService
    self._gcs_node_info_stub = None
    self._gcs_rpc_error_counter = 0
    # Public attributes are accessible for all head modules.
    # Walkaround for issue: https://github.com/ray-project/ray/issues/7084
    self.http_host = "127.0.0.1" if http_host == "localhost" else http_host
    self.http_port = http_port
    self.http_port_retries = http_port_retries
    self.redis_address = dashboard_utils.address_tuple(redis_address)
    self.redis_password = redis_password
    self.log_dir = log_dir
    self.aioredis_client = None
    self.aiogrpc_gcs_channel = None
    self.http_session = None
    self.ip = ray._private.services.get_node_ip_address()
    self.server = aiogrpc.server(options=(("grpc.so_reuseport", 0),))
    self.grpc_port = self.server.add_insecure_port("[::]:0")
    logger.info("Dashboard head grpc address: %s:%s", self.ip, self.grpc_port)