code: def test_handle_early_detect_failure(shutdown_ray):
      """Check that handle can be notified about replicas failure.
  
      It should detect replica raises ActorError and take them out of the replicas set.
      """
  
      @serve.deployment(num_replicas=2, max_concurrent_queries=1)
      def f(do_crash: bool = False):
          if do_crash:
              os._exit(1)
          return os.getpid()
  
      handle = serve.run(f.bind())
      pids = ray.get(
          [handle.remote()._to_object_ref_sync() for _ in range(2)]
      )
      assert len(set(pids)) == 2
  
      client = _get_global_client()
      # Kill the controller so that the replicas membership won't be updated
      # through controller health check + long polling.
      ray.kill(client._controller, no_restart=True)
  
      with pytest.raises(RayActorError):
          handle.remote(do_crash=True).result()
  
      pids = ray.get(
          [handle.remote()._to_object_ref_sync() for _ in range(10)]
      )
      assert len(set(pids)) == 1
  
      # Restart the controller, and then clean up all the replicas
      serve.shutdown()
  
imports: import os
  import subprocess
  import sys
  from contextlib import contextmanager
  from tempfile import NamedTemporaryFile
  import pytest
  import requests
  import ray
  import ray._private.state
  import ray.actor
  from ray import serve
  from ray._private.test_utils import SignalActor, wait_for_condition
  from ray.cluster_utils import AutoscalingCluster, Cluster
  from ray.exceptions import RayActorError
  from ray.serve._private.common import ProxyStatus
  from ray.serve._private.constants import SERVE_DEFAULT_APP_NAME
  from ray.serve._private.logging_utils import get_serve_logs_dir
  from ray.serve._private.utils import get_head_node_id
  from ray.serve.context import _get_global_client
  from ray.serve.schema import ServeInstanceDetails
  from ray.tests.conftest import call_ray_stop_only
label_desc: Use image node_id 7 for calling a global function with example usage: test_handle_early_detect_failure(shutdown_ray) and returns: os