fix: Fix gRPC handler thread stall on completion queue shutdown #8495
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: