Loading
fix(messaging): release pub/sub sockets to stop fd exhaustion (#409)
Async publishers/subscribers were never garbage collected because a ZMQ socket registered with an event loop is kept alive by that loop, and no close path existed. Each abandoned client held a file descriptor, so a process creating many pub/subs eventually hit the ~1024 fd limit and could not open new sockets.
- Add close() to the ZMQ publisher/subscriber classes, registered via weakref.finalize so the socket is also closed when the object is released, and declare close() on the messaging protocols.
- Reuse one async publisher per (event loop, uri): a WeakKeyDictionary keyed on the loop object (weakly, avoiding id() recycling) holds a WeakValueDictionary of publishers, so only one lives per loop while idle ones are still reclaimable.
- RemotePublisherAsync gains a no-op close() (no persistent socket).
- Tests cover reuse, fd release on explicit close, and release on garbage collection.
Closes #409 (closed)
Edited by Kristian Gogora