Skip to content

Heartbeat._check_heartbeat reports server down when only the socket close fails #4726

@Yicong-Huang

Description

@Yicong-Huang

What happened?

amber/src/main/python/core/runnables/heartbeat.py::Heartbeat._check_heartbeat wraps both socket.create_connection and the subsequent temp_socket.close() in a single try/except. If close() raises after a successful connect, the method logs "Server is down" and returns False even though the JVM is reachable. The double-check in run() masks transient cases but the misclassification can still trigger unwarranted shutdowns.

How to reproduce?

from unittest.mock import patch, MagicMock
from threading import Event
from core.runnables.heartbeat import Heartbeat

hb = Heartbeat("localhost", 12345, 0.1, Event())
sock = MagicMock()
sock.close.side_effect = OSError("close failed")
with patch("core.runnables.heartbeat.socket.create_connection", return_value=sock):
    print(hb._check_heartbeat())  # False, log says "Server is down"

Version

1.1.0-incubating (Pre-release/Master)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions