Fixed a flaky test where the master in a cluster cannot mark a slave as alive after receiving heartbeat from the slave.

Made heartbeat listeners to respond instance failure in the main thread.