From 4314a59327ad7425f1d990d3e006dcf8453db9b1 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 3 Oct 2023 10:54:46 -0400 Subject: [PATCH] Add post-mortem catch around failed transport addr binds to aid with runtime debugging --- tractor/_root.py | 12 ++++++++---- tractor/_runtime.py | 21 +++++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/tractor/_root.py b/tractor/_root.py index b117c2c9..bf2f883e 100644 --- a/tractor/_root.py +++ b/tractor/_root.py @@ -260,10 +260,14 @@ async def ping_tpt_socket( # start the actor runtime in a new task async with trio.open_nursery() as nursery: - # ``_runtime.async_main()`` creates an internal nursery and - # thus blocks here until the entire underlying actor tree has - # terminated thereby conducting structured concurrency. - + # ``_runtime.async_main()`` creates an internal nursery + # and blocks here until any underlying actor(-process) + # tree has terminated thereby conducting so called + # "end-to-end" structured concurrency throughout an + # entire hierarchical python sub-process set; all + # "actor runtime" primitives are SC-compat and thus all + # transitively spawned actors/processes must be as + # well. await nursery.start( partial( async_main, diff --git a/tractor/_runtime.py b/tractor/_runtime.py index 0f8cc7ae..bd626440 100644 --- a/tractor/_runtime.py +++ b/tractor/_runtime.py @@ -1405,13 +1405,22 @@ async def async_main( # - root actor: the ``accept_addr`` passed to this method assert accept_addrs - actor._server_n = await service_nursery.start( - partial( - actor._serve_forever, - service_nursery, - listen_sockaddrs=accept_addrs, + try: + actor._server_n = await service_nursery.start( + partial( + actor._serve_forever, + service_nursery, + listen_sockaddrs=accept_addrs, + ) ) - ) + except OSError as oserr: + # NOTE: always allow runtime hackers to debug + # tranport address bind errors - normally it's + # something silly like the wrong socket-address + # passed via a config or CLI Bo + entered_debug = await _debug._maybe_enter_pm(oserr) + raise + accept_addrs: list[tuple[str, int]] = actor.accept_addrs # NOTE: only set the loopback addr for the