# Buggy code
def __init__(
    self,
    redis_address,
    autoscaling_config,
    redis_password=None,
    prefix_cluster_info=False,
):
    # Initialize the Redis clients.
    ray.state.state._initialize_global_state(
        redis_address, redis_password=redis_password
    )
    self.redis = ray._private.services.create_redis_client(
        redis_address, password=redis_password
    )

    # Initialize the gcs stub for getting all node resource usage.
    gcs_address = self.redis.get("GcsServerAddress").decode("utf-8")
    gcs_channel = grpc.insecure_channel(gcs_address)
    self.gcs_node_resources_stub = gcs_service_pb2_grpc.NodeResourceInfoGcsServiceStub(
        gcs_channel
    )

    # Set the redis client and mode so _internal_kv works for autoscaler.
    worker = ray.worker.global_worker
    worker.redis_client = self.redis
    worker.mode = 0
    head_node_ip = redis_address.split(":")[0]
    self.load_metrics = LoadMetrics(local_ip=head_node_ip)
    self.last_avail_resources = None
    self.event_summarizer = EventSummarizer()
    self.prefix_cluster_info = prefix_cluster_info
    self.autoscaling_config = autoscaling_config
    self.autoscaler = None

    logger.info("Monitor: Started")


# Traceback (grpc._channel._InactiveRpcError)
In [1]: import ray

In [2]: ray.init()
2021-02-25 22:41:24,961 INFO services.py:1226 -- View the Ray dashboard at http://127.0.0.1:8265
2021-02-25 22:41:26,775 WARNING worker.py:1063 -- The autoscaler failed with the following error:
Traceback (most recent call last):
File "/home/lxy/git_repository/ray/python/ray/monitor.py", line 272, in run
self._run()
File "/home/lxy/git_repository/ray/python/ray/monitor.py", line 166, in _run
self.update_load_metrics()
File "/home/lxy/git_repository/ray/python/ray/monitor.py", line 131, in update_load_metrics
request, timeout=4)
File "/home/lxy/miniconda3/envs/ray/lib/python3.7/site-packages/grpc/_channel.py", line 826, in __call__
return _end_unary_response_blocking(state, call, False, None)
File "/home/lxy/miniconda3/envs/ray/lib/python3.7/site-packages/grpc/_channel.py", line 729, in _end_unary_response_blocking
raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "Socket closed"
debug_error_string = "{"created":"@1614264084.283816946","description":"Error received from peer ipv4:10.239.4.80:913","file":"src/core/lib/surface/call.cc","file_line":1062,"grpc_message":"Socket closed","grpc_status":14}"


# Fixed code
def __init__(
    self,
    redis_address,
    autoscaling_config,
    redis_password=None,
    prefix_cluster_info=False,
):
    # Initialize the Redis clients.
    ray.state.state._initialize_global_state(
        redis_address, redis_password=redis_password
    )
    self.redis = ray._private.services.create_redis_client(
        redis_address, password=redis_password
    )

    # Initialize the gcs stub for getting all node resource usage.
    gcs_address = self.redis.get("GcsServerAddress").decode("utf-8")
    options = (("grpc.enable_http_proxy", 0),)
    gcs_channel = grpc.insecure_channel(gcs_address, options=options)
    self.gcs_node_resources_stub = gcs_service_pb2_grpc.NodeResourceInfoGcsServiceStub(
        gcs_channel
    )

    # Set the redis client and mode so _internal_kv works for autoscaler.
    worker = ray.worker.global_worker
    worker.redis_client = self.redis
    worker.mode = 0
    head_node_ip = redis_address.split(":")[0]
    self.load_metrics = LoadMetrics(local_ip=head_node_ip)
    self.last_avail_resources = None
    self.event_summarizer = EventSummarizer()
    self.prefix_cluster_info = prefix_cluster_info
    self.autoscaling_config = autoscaling_config
    self.autoscaler = None

    logger.info("Monitor: Started")