Skip to content

Commit 66450ff

Browse files
committed
fix race condition
1 parent 379da6a commit 66450ff

1 file changed

Lines changed: 4 additions & 26 deletions

File tree

dlslime/dlslime/peer_agent/_mailbox.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ def start(self) -> None:
6363
# so losing the message stalls the handshake forever.
6464
#
6565
# Instead, _listen_loop reads from "0-0" and processes every message
66-
# on the stream. Truly stale messages from a prior crashed session
67-
# with the same alias fail endpoint.connect at handshake time — the
68-
# listen loop catches that and continues, so later in-flight qp_ready
69-
# from the current peer session still completes the handshake.
66+
# on the stream. Stale messages must be removed when the previous
67+
# agent incarnation is cleaned up. Do not use local wall-clock
68+
# timestamps here: a valid early qp_ready can predate this listener,
69+
# and sender/receiver clocks may drift across nodes.
7070
self._thread = threading.Thread(target=self._listen_loop, daemon=True)
7171
self._thread.start()
7272
logger.info(
@@ -148,15 +148,6 @@ def _listen_loop(self) -> None:
148148

149149
def _handle_message(self, fields: Dict[str, str]) -> None:
150150
"""Handle incoming stream message."""
151-
if self._is_stale_message(fields):
152-
logger.info(
153-
"StreamMailbox %s: Ignoring stale %s from %s",
154-
self._agent.alias,
155-
fields.get("type"),
156-
fields.get("peer"),
157-
)
158-
return
159-
160151
msg_type = fields.get("type")
161152

162153
if msg_type == "connect_peer":
@@ -232,18 +223,6 @@ def _handle_message(self, fields: Dict[str, str]) -> None:
232223
msg_type,
233224
)
234225

235-
def _is_stale_message(self, fields: Dict[str, str]) -> bool:
236-
raw_timestamp = fields.get("timestamp")
237-
if raw_timestamp is None:
238-
return False
239-
if isinstance(raw_timestamp, bytes):
240-
raw_timestamp = raw_timestamp.decode("utf-8", errors="replace")
241-
try:
242-
timestamp = float(raw_timestamp)
243-
except (TypeError, ValueError):
244-
return False
245-
return timestamp < getattr(self._agent, "_session_started_at", 0.0)
246-
247226
def _try_connect_peer(
248227
self,
249228
peer: str,
@@ -337,7 +316,6 @@ def _try_connect_peer_inner(
337316
"peer": self._agent.alias,
338317
"qp_info": json.dumps(my_qp_info, default=str),
339318
"conn_meta": json.dumps(my_conn_meta, default=str),
340-
"timestamp": str(time.time()),
341319
},
342320
maxlen=1000,
343321
approximate=True,

0 commit comments

Comments
 (0)