Skip to content

[AN] Remove readiness blocking on gracefulDone channel - #8664

Merged
vishalchangrani merged 3 commits into
masterfrom
mpeter/access-node-graceful-shutdown
Aug 27, 2026
Merged

[AN] Remove readiness blocking on gracefulDone channel#8664
vishalchangrani merged 3 commits into
masterfrom
mpeter/access-node-graceful-shutdown

Conversation

@m-Peter

@m-Peter m-Peter commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

Follow-up on #8662 .

On #8662 (comment), I suggested that <-gracefulDone is better to be moved outside the select, but after carefully revisiting the unit tests, it should in fact be removed entirely, as it can still block after the timeout.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes

    • Improved server shutdown behavior when active streams exceed the graceful shutdown timeout.
    • Prevented shutdown from waiting unnecessarily after forced termination.
    • Reduced delays when terminating servers with streams that do not complete promptly.
    • Improved cancellation handling for delayed streaming operations during shutdown.
  • Tests

    • Expanded shutdown coverage for delayed active streams, interceptor cancellation, and immediate shutdown with no active streams.

@m-Peter m-Peter self-assigned this Aug 23, 2026
@m-Peter
m-Peter requested a review from a team as a code owner August 23, 2026 14:22
@m-Peter m-Peter added the Bugfix label Aug 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 30098368-4160-4684-94c3-60c7591f5108

📥 Commits

Reviewing files that changed from the base of the PR and between 54cdafe and 9dec934.

📒 Files selected for processing (1)
  • module/grpcserver/server_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • module/grpcserver/server_test.go

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The shutdown worker returns after g.server.Stop() on the timeout path. Streaming shutdown tests add configurable handler delays for active-stream, interceptor-cancellation, and no-active-stream scenarios.

Changes

gRPC shutdown behavior

Layer / File(s) Summary
Force-stop shutdown and test coverage
module/grpcserver/server.go, module/grpcserver/server_test.go
The timeout path no longer waits for the graceful-stop goroutine after force-stopping the server. Test streaming handlers support blocking delays, and shutdown tests configure delays for active-stream, interceptor, and no-active-stream scenarios.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 9dec9

This localized change removes a shutdown wait that can block past its timeout; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: vishalchangrani

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: removing the blocking wait on the gracefulDone channel during graceful shutdown.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mpeter/access-node-graceful-shutdown

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.


rawServer := grpc.NewServer()
handler := &blockingStreamServer{started: make(chan struct{})}
handler := &blockingStreamServer{

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By adding <-gracefulDone as the final statement on shutdownWorker, this test (TestGrpcServerShutdown_WithActiveStream), fails with:

could not close done channel on time: failed to shutdown all components on time

showcasing the blocking that was still possible.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

func (s *blockingStreamServer) Stream(stream grpc.ServerStream) error {
close(s.started)
if s.blockDuration > 0 {
time.Sleep(s.blockDuration)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides blocking on the done channel readiness, also add some artificial blocking with time.Sleep, whenever configured.

Comment thread module/grpcserver/server_test.go
m-Peter and others added 2 commits August 26, 2026 09:17
@m-Peter m-Peter changed the title [AN] Remove entirely readiness blocking on gracefulDone channel [AN] Remove readiness blocking on gracefulDone channel Aug 26, 2026
@vishalchangrani
vishalchangrani added this pull request to the merge queue Aug 27, 2026
Merged via the queue into master with commit 7b1c658 Aug 27, 2026
62 checks passed
@vishalchangrani
vishalchangrani deleted the mpeter/access-node-graceful-shutdown branch August 27, 2026 21:19
vishalchangrani added a commit that referenced this pull request Aug 28, 2026
* fix the graceful shutdown by adding a timeout

* make tidy

* cancel streaming RPCs on shutdown via interceptor

Adds a StreamServerInterceptor that couples stream.Context() to the
node's SignalerContext, so long-lived subscriptions exit cleanly when
shutdown begins. GracefulStop then completes without needing the
force-stop fallback in the common case. The 5s timeout remains as a
backstop for any hung RPCs.

Also defaults NewGrpcServer's timeout when zero, switches the shutdown
timer to time.NewTimer to avoid a leak on the fast path, and brackets
type references in godocs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* drop unnecessary godoc and whitespace changes

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* address review comments

* Remove entirely blocking on gracefulDone channel readiness

* Update comment regarding time.Sleep on Stream()

Co-authored-by: Leo Zhang <zhangchiqing@gmail.com>

* Fix linting issue around comment

---------

Co-authored-by: Leo Zhang (zhangchiqing) <zhangchiqing@gmail.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Ardit Marku <markoupetr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants