Guard `reg_portal` for `None` in `maybe_open_portal()`

Fix potential `AttributeError` when `query_actor()` yields
a `None` portal (peer-found-locally path) and an `OSError`
is raised during transport connect.

Also,
- fix `Arbiter.delete_addr()` return type to
  `tuple[str, str]|None` bc it can return `None`.
- fix "registar" typo -> "registrar" in comment.

(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
multicast_revertable_streams
Gud Boi 2026-03-17 17:26:57 -04:00
parent d929fb75b5
commit 850219f60c
2 changed files with 20 additions and 13 deletions

View File

@ -222,8 +222,9 @@ async def maybe_open_portal(
# to) indicate that the target actor can't be
# contacted at that addr.
except OSError:
# NOTE: ensure we delete the stale entry from the
# registar actor.
# NOTE: ensure we delete the stale entry
# from the registrar actor when available.
if reg_portal is not None:
uid: tuple[str, str] = await reg_portal.run_from_ns(
'self',
'delete_addr',
@ -234,6 +235,12 @@ async def maybe_open_portal(
f'addr: {addr!r}\n'
f'uid: {uid!r}\n'
)
else:
log.warning(
f'Connection to {addr!r} failed'
f' and no registry portal available'
f' to delete stale entry.'
)
yield None

View File

@ -2038,7 +2038,7 @@ class Arbiter(Actor):
async def delete_addr(
self,
addr: tuple[str, int|str],
) -> tuple[str, str]:
) -> tuple[str, str]|None:
uid: tuple | None = self._registry.inverse.pop(
addr,
None,