Skip to content

Commit ffd37a8

Browse files
committed
bomb heartbeat, we got no heart
1 parent f5fabfc commit ffd37a8

1 file changed

Lines changed: 3 additions & 56 deletions

File tree

src/cortex/discovery/client.py

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import asyncio
99
import contextlib
1010
import logging
11-
import threading
1211
import time
1312

1413
import zmq
@@ -53,12 +52,6 @@ def __init__(
5352

5453
self._context: zmq.Context = zmq.Context()
5554
self._socket: zmq.Socket | None = None
56-
self._lock = threading.Lock()
57-
58-
# Heartbeat thread for registered topics
59-
self._heartbeat_topics: dict[str, bool] = {}
60-
self._heartbeat_thread: threading.Thread | None = None
61-
self._heartbeat_running = False
6255

6356
# Connect immediately
6457
self._connect()
@@ -89,10 +82,9 @@ def _send_request(self, request: DiscoveryRequest) -> DiscoveryResponse:
8982

9083
for attempt in range(self.retries):
9184
try:
92-
with self._lock:
93-
self._socket.send(request.to_bytes())
94-
response_bytes = self._socket.recv()
95-
return DiscoveryResponse.from_bytes(response_bytes)
85+
self._socket.send(request.to_bytes())
86+
response_bytes = self._socket.recv()
87+
return DiscoveryResponse.from_bytes(response_bytes)
9688
except zmq.Again:
9789
# Timeout - need to reconnect because REQ socket is now stuck
9890
last_error = TimeoutError(
@@ -125,8 +117,6 @@ def register_topic(self, topic_info: TopicInfo) -> bool:
125117
try:
126118
response = self._send_request(request)
127119
if response.status == DiscoveryStatus.OK:
128-
# Start heartbeat for this topic
129-
self._start_heartbeat(topic_info.name)
130120
logger.info(f"Registered topic: {topic_info.name}")
131121
return True
132122
else:
@@ -146,9 +136,6 @@ def unregister_topic(self, topic_name: str) -> bool:
146136
Returns:
147137
True if unregistration was successful
148138
"""
149-
# Stop heartbeat for this topic
150-
self._stop_heartbeat(topic_name)
151-
152139
request = DiscoveryRequest(
153140
command=DiscoveryCommand.UNREGISTER_TOPIC, topic_name=topic_name
154141
)
@@ -270,48 +257,8 @@ def list_topics(self) -> list[TopicInfo]:
270257
logger.error(f"Failed to list topics: {e}")
271258
return []
272259

273-
def _start_heartbeat(self, topic_name: str) -> None:
274-
"""Start sending heartbeats for a topic."""
275-
self._heartbeat_topics[topic_name] = True
276-
277-
if not self._heartbeat_running:
278-
self._heartbeat_running = True
279-
self._heartbeat_thread = threading.Thread(
280-
target=self._heartbeat_loop, daemon=True
281-
)
282-
self._heartbeat_thread.start()
283-
284-
def _stop_heartbeat(self, topic_name: str) -> None:
285-
"""Stop sending heartbeats for a topic."""
286-
self._heartbeat_topics.pop(topic_name, None)
287-
288-
def _heartbeat_loop(self) -> None:
289-
"""Background thread that sends heartbeats for registered topics."""
290-
while self._heartbeat_running and self._heartbeat_topics:
291-
for topic_name in list(self._heartbeat_topics.keys()):
292-
if not self._heartbeat_running:
293-
break
294-
if topic_name in self._heartbeat_topics:
295-
self._send_heartbeat(topic_name)
296-
297-
time.sleep(10.0) # Heartbeat interval
298-
299-
def _send_heartbeat(self, topic_name: str) -> None:
300-
"""Send a heartbeat for a topic."""
301-
request = DiscoveryRequest(
302-
command=DiscoveryCommand.HEARTBEAT, topic_name=topic_name
303-
)
304-
305-
try:
306-
self._send_request(request)
307-
except Exception as e:
308-
logger.warning(f"Failed to send heartbeat for {topic_name}: {e}")
309-
310260
def close(self) -> None:
311261
"""Close the client connection."""
312-
self._heartbeat_running = False
313-
self._heartbeat_topics.clear()
314-
315262
if self._socket:
316263
with contextlib.suppress(Exception):
317264
self._socket.close()

0 commit comments

Comments
 (0)