fix: Fix gRPC handler thread stall on completion queue shutdown#8495
Open
TheRobotCarlson wants to merge 2 commits intotriton-inference-server:mainfrom
Open
fix: Fix gRPC handler thread stall on completion queue shutdown#8495TheRobotCarlson wants to merge 2 commits intotriton-inference-server:mainfrom
TheRobotCarlson wants to merge 2 commits intotriton-inference-server:mainfrom
Conversation
#### What does the PR do? Resolves race condition where alarm events scheduled on a shutting-down completion queue could cause handler threads to block indefinitely, resulting in gRPC request timeouts while HTTP continued to work. When InferResponseComplete callbacks executed during server shutdown, they called PutTaskBackToQueue which scheduled alarms via alarm_.Set() on the completion queue. If this occurred after cq_->Shutdown() was called, the alarm would register but events might never be delivered, causing handler threads to block forever in cq_->Next() waiting for events that would never arrive. This PR adds an atomic shutdown flag to gate alarm scheduling, tracks active alarms for cancellation, and replaces blocking cq_->Next() with deadline-based cq_->AsyncNext() to allow periodic shutdown checks. #### Checklist - [x] I have read the Contribution guidelines and signed the Contributor License Agreement - [x] PR title reflects the change and is of format `<commit_type>: <Title>` - [x] Changes are described in the pull request. - [x] Related issues are referenced. - [ ] Populated github labels field - [x] Added test plan and verified test passes. - [ ] Verified that the PR passes existing CI. - [x] I ran pre-commit locally (`pre-commit install, pre-commit run --all`) - [x] Verified copyright is correct on all changed files. - [x] Added succinct git squash message before merging. - [x] All template sections are filled out. - [ ] Optional: Additional screenshots for behavior/output changes with before/after. #### Commit Type: - [ ] build - [ ] ci - [ ] docs - [ ] feat - [x] fix - [ ] perf - [ ] refactor - [ ] revert - [ ] style - [ ] test #### Related PRs: None #### Where should the reviewer start? - src/grpc/infer_handler.h: Review shutdown guard system, alarm tracking, and deadline-based polling changes - src/grpc/infer_handler.cc: Check PutTaskBackToQueue gating in InferResponseComplete - src/grpc/stream_infer_handler.cc: Check PutTaskBackToQueue gating in StreamInferResponseComplete (3 locations) - src/grpc/grpc_server.cc: Verify NotifyCQShutdown() is called before cq_->Shutdown() #### Test plan: - Verified no compilation errors - Stress test: continuous gRPC requests during shutdown cycles - Expected: no timeouts, clean shutdown, no resource leaks #### Caveats: - Adds 100ms polling timeout which introduces negligible latency during idle periods - Minimal overhead from O(1) atomic operations and hash set lookups #### Background Users reported intermittent gRPC timeout issues during server shutdown or reconfiguration. The root cause was handler threads becoming permanently blocked waiting for completion queue events that would never arrive due to alarms being scheduled after the queue was shut down. #### Related Issues: - closes GitHub issue: triton-inference-server#6899
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.
What does the PR do?
Resolves race condition where alarm events scheduled on a shutting-down completion queue could cause handler threads to block indefinitely, resulting in gRPC request timeouts while HTTP continued to work.
When InferResponseComplete callbacks executed during server shutdown, they called PutTaskBackToQueue which scheduled alarms via alarm_.Set() on the completion queue. If this occurred after cq_->Shutdown() was called, the alarm would register but events might never be delivered, causing handler threads to block forever in cq_->Next() waiting for events that would never arrive.
This PR adds an atomic shutdown flag to gate alarm scheduling, tracks active alarms for cancellation, and replaces blocking cq_->Next() with deadline-based cq_->AsyncNext() to allow periodic shutdown checks.
Checklist
<commit_type>: <Title>pre-commit install, pre-commit run --all)Commit Type:
Related PRs:
None
Where should the reviewer start?
Test plan:
Caveats:
Related Issues: