[Bug]: RPCClient.close hangs with an in-flight remote_future request
RPCClient.close() stops the response event loop before waiting for its worker pool. With an in-flight unary RPC, the worker remains blocked on a future that can no longer finish, so close does not return even after the server completes its method. A tested patch settles pending calls before stopping the loop.
System Info
- TensorRT-LLM Python source: main
9fd891783959eed960a6c58144241db38f9b1580. - Python 3.12, Torch
2.14.0+cu132, official TensorRT-LLM wheel1.4.0rc1.dev202610140007. - CPU-only reproduction with real HMAC/ZMQ IPC; no model or GPU required.
- The wheel's native build
da676ffbis 39 commits older than the Python source. This is not a matched source build.
Information / Tasks
Custom regression tests of RPC client shutdown, using the real RPCServer/RPCClient classes.
Reproduction
An in-flight remote_future() call occupies a client pool worker waiting on the private event loop's future. RPCClient.close() stops that loop before self._executor.shutdown(wait=True), leaving the worker without a completion/cancellation path.
- Start an RPCServer whose async method signals that it has received a request, then waits at a bounded release gate.
- Call that method with
remote_future()and wait for the server's signal. - Call
client.close()from another thread, then release the server method. - The server method finishes, but close still waits: its event-loop thread has exited,
_pending_futureshas one entry, the returned future is unfinished, and one executor worker remains alive.
The candidate’s executable regression test (test_close_finishes_active_and_queued_futures) provides the executable reproduction with a single executor worker and a second queued call. Copying the same test file onto the unmodified base reproduces the failure. Its teardown explicitly rescues stopped-loop waiters to avoid hanging pytest; the recorded failing condition precedes that cleanup.
Expected behavior
Closing the client should finish pending unary calls with RPCCancelled, release its executor/loop threads, and reject subsequent unary calls. Completed results should remain available.
Actual behavior
The close call waits after the server method has completed because the loop needed to settle its future has already stopped. An ordinary caller-loop remote_async() waiter also receives no close notification.
Additional notes
I have a narrowly scoped candidate that registers unary calls before socket send, serializes admission with close, cancels only still-active RPC callers, and drains queued executor work before stopping the loop. It leaves stats/KV-events logic and the server unchanged. A delayed cancellation callback rechecks ownership so it cannot cancel unrelated work after the caller's RPC has returned.
With the identical final tests: 7 fail / 2 pass on the base; all 9 pass with the candidate. Another 23 existing RPC checks pass, 2 skip. Applicable repository pre-commit checks pass. These are CPU lifecycle tests, not inference performance measurements; full upstream CI has not run.
I checked related work, including #8711 (existing streaming shutdown handling), #20158 (worker-owned stats server shutdown), #19764 (iteration writer shutdown), and #19723 (stats fetch ownership). Those do not settle ordinary in-flight RPCClient calls before stopping the client loop.
Would this unary-client lifecycle scope be approved for a separate PR? The candidate was implemented and tested with AI assistance; no upstream PR has been opened.