Fix JSONRPC server shutdown race - #13461
Merged
Merged
Conversation
JSONRPC server shutdown can race with worker thread startup. When the worker starts after stop_thread(), it restores the running flag and polls a closed socket indefinitely. This causes test_jsonrpcserver and process shutdown to hang. This marks the socket server as running before the worker is created, so a concurrent stop cannot be overwritten. It also passes the owning server to the worker instead of relying on the mutable global server pointer.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/mgmt/rpc/server/RPCServer.cc:67
- The worker thread runs the optional cb_init (e.g. TSThreadInit) and stores the returned handle in _rpcThread, but the matching cb_destroy is never invoked. For TSThreadDestroy specifically, the API requires the same thread that created the TSThread to destroy it (see src/api/InkIOCoreAPI.cc:202-205), so destroying it from stop_thread (caller thread) would be incorrect. This should be cleaned up in the worker thread after _socketImpl->run() returns to avoid leaking per-thread state and to respect the required destroy-thread affinity.
if (server->_init) {
server->_rpcThread = server->_init();
}
server->_socketImpl->run();
Dbg(dbg_ctl, "Socket stopped");
cmcfarlen
approved these changes
Jul 30, 2026
cmcfarlen
pushed a commit
to cmcfarlen/trafficserver
that referenced
this pull request
Jul 30, 2026
JSONRPC server shutdown can race with worker thread startup. When the worker starts after stop_thread(), it restores the running flag and polls a closed socket indefinitely. This causes test_jsonrpcserver and process shutdown to hang. This marks the socket server as running before the worker is created, so a concurrent stop cannot be overwritten. It also passes the owning server to the worker instead of relying on the mutable global server pointer. (cherry picked from commit 8b9a007)
Contributor
|
Cherry-picked to the 10.2.x branch as 1427ebf for the 10.2.0 release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JSONRPC server shutdown can race with worker thread startup. When the
worker starts after stop_thread(), it restores the running flag and
polls a closed socket indefinitely. This causes test_jsonrpcserver and
process shutdown to hang.
This marks the socket server as running before the worker is created,
so a concurrent stop cannot be overwritten. It also passes the owning
server to the worker instead of relying on the mutable global server
pointer.