Skip to content

fix: suppress context cancellation errors during graceful shutdown#153

Merged
jhaynie merged 1 commit intomainfrom
task/fix-error-report-775
Jan 27, 2026
Merged

fix: suppress context cancellation errors during graceful shutdown#153
jhaynie merged 1 commit intomainfrom
task/fix-error-report-775

Conversation

@jhaynie
Copy link
Member

@jhaynie jhaynie commented Jan 27, 2026

Summary

Fixes context cancellation errors being logged at ERROR level during graceful shutdown of the gravity client.

Changes

  • Added isContextCanceled() helper function to detect context cancellation errors (including wrapped errors)
  • Modified Start() method to log context cancellation at DEBUG level instead of ERROR
  • This prevents misleading error messages like failed to establish control stream: context canceled during normal shutdown

Related

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of context cancellation during client startup, ensuring graceful shutdown and proper cleanup when operations are canceled.
    • Reduced verbose logging for cancellation-related errors during initialization.

✏️ Tip: You can customize this high-level summary in your review settings.

When the gravity client is shut down gracefully (context cancelled), the
gRPC streams return 'context canceled' errors. These are expected during
shutdown and should not be logged at ERROR level.

Changes:
- Add isContextCanceled() helper to detect context cancellation from
  various sources (direct context.Canceled, gRPC codes.Canceled)
- Check for context cancellation in Start() before logging errors
- Log at DEBUG level instead of ERROR for graceful shutdown
- Return context.Canceled cleanly to allow callers to handle it

Fixes: agentuity/sdk#775
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 27, 2026

📝 Walkthrough

Walkthrough

The change introduces context cancellation detection in the gRPC client startup flow. A new isContextCanceled() helper function identifies context cancellation from local contexts or gRPC status codes. Contextual checks are integrated into critical startup methods to detect cancellation early and perform graceful cleanup instead of logging as normal failures.

Changes

Cohort / File(s) Change Summary
Context Cancellation Handling
gravity/grpc_client.go
Added isContextCanceled() helper to detect context cancellation; integrated cancellation checks in Start(), establishControlStreams(), sendSessionHello(), and establishTunnelStreams() methods to gracefully handle early termination and cleanup
Dependencies
go.mod
Dependency updates
🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c86a93 and 7f05810.

📒 Files selected for processing (1)
  • gravity/grpc_client.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: Analyze (go)
🔇 Additional comments (5)
gravity/grpc_client.go (5)

53-66: LGTM! Well-designed helper for comprehensive cancellation detection.

The function correctly handles cancellation from multiple sources: direct context cancellation, wrapped errors via errors.Is(), and gRPC-specific status codes. This consolidates the cancellation detection logic that was previously scattered or incomplete.


432-437: LGTM! Graceful cancellation handling for control streams.

The pattern correctly detects context cancellation, logs at DEBUG level to avoid misleading ERROR logs, performs cleanup, and returns context.Canceled for proper caller handling.


448-453: LGTM!

Consistent pattern with the control streams handling. The cancellation will be properly detected even though sendSessionHello() uses context.Background() for retries, since the underlying stream is derived from g.ctx.


464-469: LGTM!

Completes the graceful shutdown handling for all startup phases with consistent implementation.


525-528: LGTM! Appropriate conditional logging.

This prevents misleading ERROR logs during graceful shutdown while still logging actual errors. The error is properly propagated to the caller where it receives appropriate handling.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • REPORT-775: Entity not found: Issue - Could not find referenced Issue.

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

@jhaynie jhaynie merged commit 09798c1 into main Jan 27, 2026
5 checks passed
@jhaynie jhaynie deleted the task/fix-error-report-775 branch January 27, 2026 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant