# Buggy code
def _get_node_specific_docker_config(self, node_id):
    docker_config = copy.deepcopy(self.config.get("docker", {}))
    node_specific_docker = self._get_node_type_specific_fields(node_id, "docker")
    docker_config.update(node_specific_docker)
    return docker_config


# Traceback (KeyError)
==> /tmp/ray/session_2020-09-09_17-20-39_779593_74/logs/monitor.err <==
docker_config = self._get_node_specific_docker_config(node_id)
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 431, in _get_node_specific_docker_config
node_id, "docker")
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 417, in _get_node_type_specific_fields
fields = self.config[fields_key]
KeyError: 'docker'
2020-09-09 17:21:11,100 INFO autoscaler.py:520 -- Cluster status: 1/1 target nodes (0 pending)
- MostDelayedHeartbeats: {'192.168.6.142': 0.13077020645141602}
- NodeIdleSeconds: Min=29 Mean=29 Max=29
- NumNodesConnected: 1
- NumNodesUsed: 0.0
- ResourceUsage: 0.0/3.0 CPU, 0.0 GiB/1.21 GiB memory, 0.0 GiB/0.42 GiB object_store_memory
- TimeSinceLastHeartbeat: Min=0 Mean=0 Max=0

2020-09-09 17:21:11,112 INFO autoscaler.py:520 -- Cluster status: 1/1 target nodes (0 pending)
- MostDelayedHeartbeats: {'192.168.6.142': 0.14269304275512695}
- NodeIdleSeconds: Min=29 Mean=29 Max=29
- NumNodesConnected: 1
- NumNodesUsed: 0.0
- ResourceUsage: 0.0/3.0 CPU, 0.0 GiB/1.21 GiB memory, 0.0 GiB/0.42 GiB object_store_memory
- TimeSinceLastHeartbeat: Min=0 Mean=0 Max=0

2020-09-09 17:21:11,128 ERROR autoscaler.py:123 -- StandardAutoscaler: Error during autoscaling.
Traceback (most recent call last):
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 121, in update
self._update()
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 250, in _update
self.should_update(node_id) for node_id in nodes):
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 250, in <genexpr>
self.should_update(node_id) for node_id in nodes):
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 456, in should_update
docker_config = self._get_node_specific_docker_config(node_id)
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 431, in _get_node_specific_docker_config
node_id, "docker")
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 417, in _get_node_type_specific_fields
fields = self.config[fields_key]
KeyError: 'docker'
2020-09-09 17:21:11,129 CRITICAL autoscaler.py:130 -- StandardAutoscaler: Too many errors, abort.
Error in monitor loop
Traceback (most recent call last):
File "/root/anaconda3/lib/python3.7/site-packages/ray/monitor.py", line 313, in run
self._run()
File "/root/anaconda3/lib/python3.7/site-packages/ray/monitor.py", line 268, in _run
self.autoscaler.update()
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 132, in update
raise e
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 121, in update
self._update()
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 250, in _update
self.should_update(node_id) for node_id in nodes):
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 250, in <genexpr>
self.should_update(node_id) for node_id in nodes):
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 456, in should_update
docker_config = self._get_node_specific_docker_config(node_id)
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 431, in _get_node_specific_docker_config
node_id, "docker")
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 417, in _get_node_type_specific_fields
fields = self.config[fields_key]
KeyError: 'docker'
2020-09-09 17:21:11,129 ERROR autoscaler.py:554 -- StandardAutoscaler: kill_workers triggered
2020-09-09 17:21:11,134 INFO node_provider.py:121 -- KubernetesNodeProvider: calling delete_namespaced_pod
2020-09-09 17:21:11,148 ERROR autoscaler.py:559 -- StandardAutoscaler: terminated 1 node(s)
Error in sys.excepthook:
Traceback (most recent call last):
File "/root/anaconda3/lib/python3.7/site-packages/ray/worker.py", line 834, in custom_excepthook
worker_id = global_worker.worker_id
AttributeError: 'Worker' object has no attribute 'worker_id'

Original exception was:
Traceback (most recent call last):
File "/root/anaconda3/lib/python3.7/site-packages/ray/monitor.py", line 368, in <module>
monitor.run()
File "/root/anaconda3/lib/python3.7/site-packages/ray/monitor.py", line 313, in run
self._run()
File "/root/anaconda3/lib/python3.7/site-packages/ray/monitor.py", line 268, in _run
self.autoscaler.update()
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 132, in update
raise e
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 121, in update
self._update()
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 250, in _update
self.should_update(node_id) for node_id in nodes):
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 250, in <genexpr>
self.should_update(node_id) for node_id in nodes):
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 456, in should_update
docker_config = self._get_node_specific_docker_config(node_id)
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 431, in _get_node_specific_docker_config
node_id, "docker")
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 417, in _get_node_type_specific_fields
fields = self.config[fields_key]
KeyError: 'docker'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/root/anaconda3/lib/python3.7/site-packages/ray/monitor.py", line 380, in <module>
redis_client, ray_constants.MONITOR_DIED_ERROR, message)
File "/root/anaconda3/lib/python3.7/site-packages/ray/utils.py", line 128, in push_error_to_driver_through_redis
pubsub_msg.SerializeAsString())
AttributeError: SerializeAsString

==> /tmp/ray/session_2020-09-09_17-20-39_779593_74/logs/monitor.out <==
Destroying cluster. Confirm [y/N]: y [automatic, due to --yes]
1 random worker nodes will not be shut down. (due to --keep-min-workers)
The head node will not be shut down. (due to --workers-only)
No nodes remaining.

==> /tmp/ray/session_latest/logs/monitor.err <==
docker_config = self._get_node_specific_docker_config(node_id)
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 431, in _get_node_specific_docker_config
node_id, "docker")
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 417, in _get_node_type_specific_fields
fields = self.config[fields_key]
KeyError: 'docker'
2020-09-09 17:21:11,100 INFO autoscaler.py:520 -- Cluster status: 1/1 target nodes (0 pending)
- MostDelayedHeartbeats: {'192.168.6.142': 0.13077020645141602}
- NodeIdleSeconds: Min=29 Mean=29 Max=29
- NumNodesConnected: 1
- NumNodesUsed: 0.0
- ResourceUsage: 0.0/3.0 CPU, 0.0 GiB/1.21 GiB memory, 0.0 GiB/0.42 GiB object_store_memory
- TimeSinceLastHeartbeat: Min=0 Mean=0 Max=0

2020-09-09 17:21:11,112 INFO autoscaler.py:520 -- Cluster status: 1/1 target nodes (0 pending)
- MostDelayedHeartbeats: {'192.168.6.142': 0.14269304275512695}
- NodeIdleSeconds: Min=29 Mean=29 Max=29
- NumNodesConnected: 1
- NumNodesUsed: 0.0
- ResourceUsage: 0.0/3.0 CPU, 0.0 GiB/1.21 GiB memory, 0.0 GiB/0.42 GiB object_store_memory
- TimeSinceLastHeartbeat: Min=0 Mean=0 Max=0

2020-09-09 17:21:11,128 ERROR autoscaler.py:123 -- StandardAutoscaler: Error during autoscaling.
Traceback (most recent call last):
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 121, in update
self._update()
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 250, in _update
self.should_update(node_id) for node_id in nodes):
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 250, in <genexpr>
self.should_update(node_id) for node_id in nodes):
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 456, in should_update
docker_config = self._get_node_specific_docker_config(node_id)
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 431, in _get_node_specific_docker_config
node_id, "docker")
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 417, in _get_node_type_specific_fields
fields = self.config[fields_key]
KeyError: 'docker'
2020-09-09 17:21:11,129 CRITICAL autoscaler.py:130 -- StandardAutoscaler: Too many errors, abort.
Error in monitor loop
Traceback (most recent call last):
File "/root/anaconda3/lib/python3.7/site-packages/ray/monitor.py", line 313, in run
self._run()
File "/root/anaconda3/lib/python3.7/site-packages/ray/monitor.py", line 268, in _run
self.autoscaler.update()
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 132, in update
raise e
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 121, in update
self._update()
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 250, in _update
self.should_update(node_id) for node_id in nodes):
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 250, in <genexpr>
self.should_update(node_id) for node_id in nodes):
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 456, in should_update
docker_config = self._get_node_specific_docker_config(node_id)
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 431, in _get_node_specific_docker_config
node_id, "docker")
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 417, in _get_node_type_specific_fields
fields = self.config[fields_key]
KeyError: 'docker'
2020-09-09 17:21:11,129 ERROR autoscaler.py:554 -- StandardAutoscaler: kill_workers triggered
2020-09-09 17:21:11,134 INFO node_provider.py:121 -- KubernetesNodeProvider: calling delete_namespaced_pod
2020-09-09 17:21:11,148 ERROR autoscaler.py:559 -- StandardAutoscaler: terminated 1 node(s)
Error in sys.excepthook:
Traceback (most recent call last):
File "/root/anaconda3/lib/python3.7/site-packages/ray/worker.py", line 834, in custom_excepthook
worker_id = global_worker.worker_id
AttributeError: 'Worker' object has no attribute 'worker_id'

Original exception was:
Traceback (most recent call last):
File "/root/anaconda3/lib/python3.7/site-packages/ray/monitor.py", line 368, in <module>
monitor.run()
File "/root/anaconda3/lib/python3.7/site-packages/ray/monitor.py", line 313, in run
self._run()
File "/root/anaconda3/lib/python3.7/site-packages/ray/monitor.py", line 268, in _run
self.autoscaler.update()
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 132, in update
raise e
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 121, in update
self._update()
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 250, in _update
self.should_update(node_id) for node_id in nodes):
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 250, in <genexpr>
self.should_update(node_id) for node_id in nodes):
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 456, in should_update
docker_config = self._get_node_specific_docker_config(node_id)
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 431, in _get_node_specific_docker_config
node_id, "docker")
File "/root/anaconda3/lib/python3.7/site-packages/ray/autoscaler/autoscaler.py", line 417, in _get_node_type_specific_fields
fields = self.config[fields_key]
KeyError: 'docker'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/root/anaconda3/lib/python3.7/site-packages/ray/monitor.py", line 380, in <module>
redis_client, ray_constants.MONITOR_DIED_ERROR, message)
File "/root/anaconda3/lib/python3.7/site-packages/ray/utils.py", line 128, in push_error_to_driver_through_redis
pubsub_msg.SerializeAsString())
AttributeError: SerializeAsString

==> /tmp/ray/session_latest/logs/monitor.out <==
Destroying cluster. Confirm [y/N]: y [automatic, due to --yes]
1 random worker nodes will not be shut down. (due to --keep-min-workers)
The head node will not be shut down. (due to --workers-only)
No nodes remaining.

# Fixed code
def _get_node_specific_docker_config(self, node_id):
    if "docker" not in self.config:
        return {}
    docker_config = copy.deepcopy(self.config.get("docker", {}))
    node_specific_docker = self._get_node_type_specific_fields(node_id, "docker")
    docker_config.update(node_specific_docker)
    return docker_config