fix(gateway): stabilize process identities

This commit is contained in:
Xubin Ren committed 2026-08-18 03:21:00 +08:00
1 parent 2b4a04fb71
commit 19ad1adfe7
3 files changed
+240 -35

No files matched your search

+18 -6
View File
@@ -535,12 +535,7 @@ class GatewayClientLease:
if not isinstance(pid, int) or not self._process_is_running(pid):
stale.append(token)
continue
current_identity = self._process_identity(pid)
if (
identity is not None
and current_identity is not None
and identity != current_identity
):
if self._process_identity_match(identity, pid) == "mismatch":
stale.append(token)
for token in stale:
clients.pop(token, None)
@@ -551,6 +546,23 @@ class GatewayClientLease:
value = resolver(pid) if callable(resolver) else None
return value if isinstance(value, (str, int)) else None
def _process_identity_match(
self,
recorded: object,
pid: int,
) -> Literal["match", "mismatch", "unknown"]:
matcher = getattr(self.runtime, "process_identity_match", None)
if callable(matcher):
result = matcher(recorded, pid)
if result in {"match", "mismatch", "unknown"}:
return cast(Literal["match", "mismatch", "unknown"], result)
if recorded is None:
return "match"
current = self._process_identity(pid)
if current is None:
return "unknown"
return "match" if recorded == current else "mismatch"
def _process_is_running(self, pid: int) -> bool:
checker = getattr(self.runtime, "process_is_running", None)
return bool(checker(pid)) if callable(checker) else process_is_running(pid)