Skip to content

Remove nursery parameter from IListener.listen() (breaking) #1314

@yashksaini-coder

Description

@yashksaini-coder

Problem

IListener.listen(maddr, nursery) currently requires every caller to provide a trio.Nursery whose lifetime must outlive the listener. This leaks listener background-task ownership into callers, makes per-listener cleanup ambiguous, and conflicts with
transports (QUIC) that already manage their own background work.

Tracked in Discussion #726 (Issue 1).

Proposal

Drop the nursery parameter from IListener.listen(). Concrete listeners (TCP, WebSocket, QUIC, Circuit Relay v2) own their own background tasks internally via trio.lowlevel.spawn_system_task and are torn down via an explicit close() call.

Acceptance criteria

  • IListener.listen(maddr) no longer accepts a nursery parameter.
  • TCPListener, WebSocketListener, QUICListener, and CircuitV2Listener own their background task lifetimes internally.
  • Swarm shutdown calls listener.close() explicitly on every listener.
  • Breaking-change newsfragment shipped under newsfragments/<this-issue>.breaking.rst.
  • Callers in tests/utils/factories.py and example code migrated.
  • TCPListener correctly handles repeated listen() calls on the same instance (multi-bind contract) without leaking orphaned nurseries.

Implementing PR

#1308

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions