You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(transport): remove nursery param from IListener.listen (adopts #1055) (#1308)
* refactor(abc): remove nursery parameter from IListener.listen
The caller-supplied nursery was a leaky abstraction that forced Swarm
to manage a listener_nursery on behalf of every transport. Listeners
should own their own background task lifetimes internally.
This commit updates the interface only; concrete implementations follow
in subsequent commits. Part of #726.
Co-authored-by: Michael Eze <code.maestro64@gmail.com>
* refactor(transport/tcp): move nursery ownership inside TCPListener
TCPListener now spawns its own internal nursery as a trio system task
in listen(). The nursery hosts trio.serve_tcp and stays open until
close() cancels it.
listen() drops the nursery parameter and returns once the socket is
bound (signalled via an internal trio.Event). Startup errors are
captured and re-raised as OpenConnectionError to preserve the existing
error contract.
close() cancels the internal nursery, closes all SocketListeners, and
waits for the background system task to finish so callers observe a
fully-quiesced listener on return. Safe to call multiple times.
Part of #726.
Co-authored-by: Michael Eze <code.maestro64@gmail.com>
* refactor(transport/websocket): move nursery ownership inside WebsocketListener
Same pattern as TCPListener: listen() drops the nursery parameter and
spawns a trio system task that hosts an internal nursery. serve_websocket
runs under that nursery until close() cancels it. Startup errors are
captured and re-raised as OpenConnectionError.
close() now also awaits the background task's completion after cancelling
the nursery, so callers observe a fully-quiesced listener on return.
Part of #726.
Co-authored-by: Michael Eze <code.maestro64@gmail.com>
* refactor(transport/quic): remove nursery param from QUICListener.listen
QUIC is a special case: the transport already carries a background
nursery via set_background_nursery(). Prefer that nursery when
available (the common path when used through a Swarm), and fall back
to a self-spawned trio system task with its own internal nursery when
it isn't. Either way, the listen() API no longer requires a caller-
supplied nursery.
close() cancels the self-spawned nursery when it was used and waits
for the background task to finish.
Part of #726.
Co-authored-by: Michael Eze <code.maestro64@gmail.com>
* refactor(relay/circuit_v2): drop unused nursery param from CircuitV2Listener.listen
The CircuitV2 listener never used the nursery parameter — it just
records the multiaddr to advertise. Drop the parameter to align with
the updated IListener interface.
Part of #726.
Co-authored-by: Michael Eze <code.maestro64@gmail.com>
* refactor(swarm): drop listener_nursery in favor of listener-owned nurseries
Listeners now own their internal nursery, so Swarm no longer manages
listener_nursery / event_listener_nursery_created. The outer nursery
in run() is still needed for transport-level background tasks (QUIC /
WebSocket set_background_nursery) and for the auto-connector, so it
is renamed to background_nursery / event_background_nursery_created to
reflect its actual purpose.
run() now also calls listener.close() on every listener during
shutdown, so their internal system-task nurseries are cancelled and
fully awaited.
listen() drops the nursery argument from its listener.listen() call.
Part of #726.
Co-authored-by: Michael Eze <code.maestro64@gmail.com>
* test(transport): drop nursery arg from all listener.listen() call sites
Updates the full test suite to match the new IListener.listen(maddr)
signature: TCP, WebSocket, QUIC listener/integration tests, shared
trio I/O fixtures, and the tests/utils/factories factory.
Part of #726.
Co-authored-by: Michael Eze <code.maestro64@gmail.com>
* docs(news): add breaking changelog entry for #726
Co-authored-by: Michael Eze <code.maestro64@gmail.com>
* fix: resolve CI lint failures (ruff F841, mypy no-redef/union-attr, format)
- test_listener.py, test_websocket.py: remove now-unused `nursery`
variable from `async with trio.open_nursery() as nursery:` blocks
(ruff F841) — listen() no longer takes a nursery parameter
- quic/listener.py: avoid re-declaring _owned_start_error with a type
annotation in listen() (mypy no-redef); capture Event objects in
local vars before entering the system-task closure so the `set()`
calls resolve against non-Optional types (mypy union-attr)
- tcp/tcp.py: ruff format reformatting
Co-authored-by: Michael Eze <code.maestro64@gmail.com>
* fix(tcp): own a single long-lived nursery across repeated listen() calls
TCPListener used to reset per-call lifecycle state and open a fresh
nursery on every listen(), orphaning earlier server tasks so close()
could only cancel the last bind. Now the background system task and
nursery are created once on first listen() and reused for subsequent
binds. close() cancels them together, is idempotent, and listen()
after close() raises OpenConnectionError.
A trio.Lock serializes concurrent listen()/close() so the lazy spawn
can't race. Adds test_tcp_listener_close_cancels_all_binds covering
multi-bind teardown, idempotent close, and post-close rejection.
Fixes the multi-bind regression acul71 flagged in the PR #1308 review.
Renames the newsfragment to match issue #1314.
* test: close listener explicitly in direct-listener tests and factory
Tests that create TCPListener directly (test_trio_real_connection and
raw_conn_factory) now call await listener.close() before letting the
enclosing nursery cancel. This exercises the new listener-owns-its-
lifetime contract and stops leaking listener tasks between tests.
Addresses acul71's review on PR #1308.
---------
Co-authored-by: Michael Eze <code.maestro64@gmail.com>
0 commit comments