Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Add recovery interceptor to grpc servers#128

Merged
mangelajo merged 1 commit intomainfrom
recover
Apr 16, 2025
Merged

Add recovery interceptor to grpc servers#128
mangelajo merged 1 commit intomainfrom
recover

Conversation

@NickCao
Copy link
Copy Markdown
Collaborator

@NickCao NickCao commented Apr 16, 2025

Summary by CodeRabbit

  • New Features

    • Improved server stability by adding automatic recovery from unexpected errors in gRPC calls, preventing crashes during RPC handling.
  • Chores

    • Upgraded and added several dependencies to enhance compatibility and reliability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 16, 2025

Walkthrough

This update introduces chained gRPC interceptors to enhance server robustness in both the ControllerService and RouterService components. The recovery middleware is now integrated alongside existing interceptors, enabling automatic panic recovery for unary and stream RPC calls. Additionally, the Go module configuration is updated: the Go version and toolchain are bumped, new direct dependencies are added, and several indirect dependencies are upgraded. No changes are made to public interfaces or exported entities; all modifications are internal or related to dependency management.

Changes

File(s) Change Summary
go.mod Updated Go version and toolchain; added new direct dependencies (go-grpc-middleware/v2, k8s.io/utils); upgraded several indirect deps.
internal/service/controller_service.go Replaced single interceptors with chained interceptors, adding recovery middleware to gRPC server setup.
internal/service/router_service.go Added recovery middleware interceptors to gRPC server options for panic recovery in unary and stream calls.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant gRPC_Server
    participant RecoveryInterceptor
    participant LogContextInterceptor
    participant Handler

    Client->>gRPC_Server: Initiate RPC (unary or stream)
    gRPC_Server->>RecoveryInterceptor: Pass request
    RecoveryInterceptor->>LogContextInterceptor: Pass request
    LogContextInterceptor->>Handler: Pass request
    Handler-->>LogContextInterceptor: Response / Panic
    LogContextInterceptor-->>RecoveryInterceptor: Response / Panic
    RecoveryInterceptor-->>gRPC_Server: Response (recover if panic)
    gRPC_Server-->>Client: Send response
Loading

Poem

🐇
In the warren of code, we hop along,
Chaining interceptors, sturdy and strong.
Recovery now guards each gRPC call,
So panics won't cause the server to fall.
Dependencies fresh, the module renewed—
This rabbit approves, with gratitude imbued!
🌱

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f23bc6 and c5d696c.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • go.mod (5 hunks)
  • internal/service/controller_service.go (2 hunks)
  • internal/service/router_service.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • internal/service/controller_service.go
  • internal/service/router_service.go
  • go.mod
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: e2e-tests-28d6b1cc3b49ab9ae176918ab9709a2e2522c97e
  • GitHub Check: e2e-tests (ubuntu-24.04-arm)
  • GitHub Check: e2e-tests (ubuntu-24.04)
  • GitHub Check: deploy-kind
  • GitHub Check: lint-go

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
internal/service/router_service.go (1)

129-130: Proper implementation of recovery interceptors.

The implementation correctly adds both unary and stream recovery interceptors to the RouterService, ensuring consistent error handling with the ControllerService.

For consistency with controller_service.go, consider placing the ServerOption before the interceptors in the parameter list:

server := grpc.NewServer(
-	grpc.Creds(credentials.NewServerTLSFromCert(cert)),
-	grpc.ChainUnaryInterceptor(recovery.UnaryServerInterceptor()),
-	grpc.ChainStreamInterceptor(recovery.StreamServerInterceptor()),
-	s.ServerOption,
+	s.ServerOption,
+	grpc.Creds(credentials.NewServerTLSFromCert(cert)),
+	grpc.ChainUnaryInterceptor(recovery.UnaryServerInterceptor()),
+	grpc.ChainStreamInterceptor(recovery.StreamServerInterceptor()),
)

Though the order of server options doesn't affect functionality, maintaining consistency across services can help with future maintainability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b98390 and 7f23bc6.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • go.mod (6 hunks)
  • internal/service/controller_service.go (2 hunks)
  • internal/service/router_service.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: e2e-tests-28d6b1cc3b49ab9ae176918ab9709a2e2522c97e
  • GitHub Check: e2e-tests (ubuntu-24.04)
  • GitHub Check: tests
  • GitHub Check: e2e-tests (ubuntu-24.04-arm)
🔇 Additional comments (8)
go.mod (4)

3-5: Go version and toolchain update looks good.

The update to Go 1.23 and specification of toolchain Go 1.24.2 is appropriate for implementing the new recovery interceptors.


14-14: Good addition of the go-grpc-middleware dependency.

This dependency provides the recovery interceptors used in the service implementations to handle panics gracefully in the gRPC servers.


29-29: k8s.io/utils is now correctly marked as a direct dependency.

Promoting this from indirect to direct dependency accurately reflects its usage in the codebase.


34-34: Dependency updates look appropriate.

The updates to indirect dependencies support the overall Go version update and the new middleware functionality.

Also applies to: 69-69, 100-100, 112-117

internal/service/controller_service.go (3)

33-33: Good import addition for recovery interceptor.

The recovery middleware will help prevent service crashes due to panics in request handlers.


683-690: Excellent implementation of chained unary interceptors with recovery.

The implementation properly chains the existing logContext interceptor with the new recovery interceptor, ensuring that panics in unary RPC handlers will be caught and handled gracefully while preserving the logging context.


691-698: Proper implementation of chained stream interceptors with recovery.

The stream interceptor chain is correctly implemented, maintaining the existing wrappedStream functionality while adding panic recovery for streaming RPCs.

internal/service/router_service.go (1)

26-26: Good import addition for recovery interceptor.

Consistent with the changes in controller_service.go, this import supports the recovery middleware functionality.

@mangelajo mangelajo merged commit 2a430f1 into main Apr 16, 2025
8 checks passed
@NickCao NickCao deleted the recover branch April 16, 2025 13:36
@mangelajo mangelajo added this to the 0.6.0 milestone May 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants