[PD] Fix ZMQ stale socket reconnection in PD disaggregation (#27796)

Signed-off-by: Shangming Cai <csmthu@gmail.com>
Co-authored-by: Abatom <abzhonghua@gmail.com>
This commit is contained in:
Shangming Cai
2026-06-11 19:51:12 +08:00
committed by GitHub
co-authored by Abatom
parent 66076f2409
commit 6a012fbb2d
2 changed files with 25 additions and 31 deletions
@@ -710,6 +710,15 @@ class CommonKVManager(BaseKVManager):
keys_to_remove = [
k for k in self.connection_pool if k.startswith(failed_bootstrap_addr)
]
# Collect TCP endpoints from cached bootstrap_infos before deletion
stale_endpoints = set()
for k in keys_to_remove:
for info in self.connection_pool[k]:
ip = info.get("rank_ip")
port = info.get("rank_port")
if ip and port:
na = NetworkAddress(ip, int(port))
stale_endpoints.add(na.to_tcp())
for k in keys_to_remove:
del self.connection_pool[k]
self.prefill_info_table.pop(failed_bootstrap_addr, None)
@@ -719,6 +728,9 @@ class CommonKVManager(BaseKVManager):
)
self.addr_to_rooms_tracker.pop(failed_bootstrap_addr, None)
for endpoint in stale_endpoints:
CommonKVReceiver.disconnect_endpoint(endpoint)
affected_rooms = []
for room in possible_affected_rooms:
if (
@@ -1082,6 +1094,19 @@ class CommonKVReceiver(BaseKVReceiver):
cls._socket_locks[endpoint] = threading.Lock()
return cls._socket_cache[endpoint], cls._socket_locks[endpoint]
@classmethod
def disconnect_endpoint(cls, endpoint: str):
with cls._global_lock:
sock = cls._socket_cache.pop(endpoint, None)
lock = cls._socket_locks.pop(endpoint, None)
if sock:
if lock:
with lock:
sock.close()
else:
sock.close()
logger.debug(f"Disconnected stale ZMQ PUSH socket (receiver): {endpoint}")
@classmethod
def _connect_to_bootstrap_server(cls, bootstrap_info: dict):
ip_address = bootstrap_info["rank_ip"]
@@ -1651,37 +1651,6 @@ class MooncakeKVManager(CommonKVManager):
):
self._run_one_probe_pass()
def _handle_node_failure(self, failed_bootstrap_addr):
with self.connection_lock:
keys_to_remove = [
k for k in self.connection_pool if k.startswith(failed_bootstrap_addr)
]
for k in keys_to_remove:
del self.connection_pool[k]
possible_affected_rooms = self.addr_to_rooms_tracker.get(
failed_bootstrap_addr, []
)
self.prefill_info_table.pop(failed_bootstrap_addr, None)
self.addr_to_rooms_tracker.pop(failed_bootstrap_addr, None)
# Report the requests associated with the failed bootstrap addr and mark their status as KVPoll.Failed
affected_rooms = []
for room in possible_affected_rooms:
if (
room in self.request_status
and self.check_status(room) != KVPoll.Success
):
self.record_failure(
room,
f"Losing connection with prefill instance (bootstrap_addr: {failed_bootstrap_addr})",
)
self.update_status(room, KVPoll.Failed)
affected_rooms.append(room)
logger.error(
f"Losing connection with prefill instance (bootstrap_addr: {failed_bootstrap_addr}), {len(affected_rooms)} requests affected"
)
class MooncakeKVSender(CommonKVSender):