Skip to content

Conversation

@TheRobotCarlson
Copy link

@TheRobotCarlson TheRobotCarlson commented Nov 6, 2025

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

  • I have read the Contribution guidelines and signed the Contributor License Agreement
  • PR title reflects the change and is of format <commit_type>: <Title>
  • Changes are described in the pull request.
  • Related issues are referenced.
  • Populated github labels field
  • Added test plan and verified test passes.
  • Verified that the PR passes existing CI.
  • I ran pre-commit locally (pre-commit install, pre-commit run --all)
  • Verified copyright is correct on all changed files.
  • Added succinct git squash message before merging.
  • All template sections are filled out.
  • Optional: Additional screenshots for behavior/output changes with before/after.

Commit Type:

  • build
  • ci
  • docs
  • feat
  • 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

Related Issues:

#### 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
@TheRobotCarlson TheRobotCarlson marked this pull request as draft November 6, 2025 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant