Skip to content

fix: don't log graceful watcher shutdown as error#2168

Merged
endigma merged 3 commits intomainfrom
jesse/eng-7975-watcher-context-cancel-ignore
Aug 26, 2025
Merged

fix: don't log graceful watcher shutdown as error#2168
endigma merged 3 commits intomainfrom
jesse/eng-7975-watcher-context-cancel-ignore

Conversation

@endigma
Copy link
Copy Markdown
Member

@endigma endigma commented Aug 26, 2025

  • fix: don't log errors when execution config watcher shuts down gracefully
  • chore: allow using .env for CDN JWT secret
  • chore: uncomment local execution config for debug JSON

Summary by CodeRabbit

  • New Features

    • CDN JWT secret is now configurable via environment variable, with a safe default fallback.
    • Router supports watching and auto-reloading the execution config file in debug mode.
  • Bug Fixes

    • Eliminated misleading error logs when config watching is canceled during shutdown; logs are clearer and reflect normal shutdown behavior.
  • Chores

    • Minor log message polish for router configuration events to improve clarity.

Checklist

@endigma endigma requested a review from JivusAyrus August 26, 2025 09:20
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 26, 2025

Walkthrough

Introduces an env-var expansion for CDN AUTH_JWT_SECRET in docker-compose, refines router watcher error handling and logging, renames a local watcher variable, and enables file-based execution config with watch enabled in router debug config.

Changes

Cohort / File(s) Summary
Router watcher and logging
router/cmd/main.go, router/core/router.go
Renamed local watcher variable (watchFunc → w) and updated usage; adjusted log message text. In Router.Start, refined error handling to detect context cancellation: logs error for non-cancel errors, debug on cancellation; maintains existing watcher callback behavior.
Configuration updates
docker-compose.yml, router/debug.config.yaml
docker-compose: switched CDN AUTH_JWT_SECRET to env expansion ${CDN_AUTH_JWT_SECRET:-fkczyomvdprgvtmvkuhvprxuggkbgwld}. router debug config: enabled execution_config.file with path ./__schemas/config.json and watch: true.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jesse/eng-7975-watcher-context-cancel-ignore

🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Aug 26, 2025

Router image scan passed

✅ No security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-ceca75cb895431af8d786861ecd72500fbab4c47

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 (4)
docker-compose.yml (1)

189-197: Consider parameterizing AUTH_ADMISSION_JWT_SECRET as well and documenting .env usage

For consistency and to make rotating local secrets easier, expose AUTH_ADMISSION_JWT_SECRET via env expansion too. Example:

       NODE_ENV: development
-      AUTH_JWT_SECRET: ${CDN_AUTH_JWT_SECRET:-fkczyomvdprgvtmvkuhvprxuggkbgwld}
-      AUTH_ADMISSION_JWT_SECRET: uXDxJLEvrw4aafPfrf3rRotCoBzRfPEW
+      AUTH_JWT_SECRET: ${CDN_AUTH_JWT_SECRET:-fkczyomvdprgvtmvkuhvprxuggkbgwld}
+      AUTH_ADMISSION_JWT_SECRET: ${CDN_AUTH_ADMISSION_JWT_SECRET:-uXDxJLEvrw4aafPfrf3rRotCoBzRfPEW}

Also consider adding CDN_AUTH_JWT_SECRET (and CDN_AUTH_ADMISSION_JWT_SECRET if you adopt the change) to an .env.example for discoverability.

I can add an .env.example snippet and a short README note if you want.

router/cmd/main.go (1)

206-211: Treat DeadlineExceeded like Canceled for graceful watcher shutdown

If a deadline is ever introduced on rootCtx, you’ll log an error on graceful exit. Consider suppressing context.DeadlineExceeded the same way you handle context.Canceled.

-            if err := w(rootCtx); err != nil {
-                if !errors.Is(err, context.Canceled) {
-                    ll.Error("Error watching router config", zap.Error(err))
-                } else {
-                    ll.Debug("Watcher context cancelled, shutting down")
-                }
-            }
+            if err := w(rootCtx); err != nil {
+                if !(errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded)) {
+                    ll.Error("Error watching router config", zap.Error(err))
+                } else {
+                    ll.Debug("Watcher context cancelled, shutting down")
+                }
+            }
router/core/router.go (2)

1204-1208: Mirror graceful-exit handling: include DeadlineExceeded

Same rationale as in cmd: treat DeadlineExceeded as a graceful shutdown to avoid spurious error logs.

-                if !errors.Is(err, context.Canceled) {
-                    ll.Error("Error watching execution config", zap.Error(err))
-                } else {
-                    ll.Debug("Watcher context cancelled, shutting down")
-                }
+                if !(errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded)) {
+                    ll.Error("Error watching execution config", zap.Error(err))
+                } else {
+                    ll.Debug("Watcher context cancelled, shutting down")
+                }

1204-1208: Optional: dedupe context-exit checks with a tiny helper

You now have identical shutdown-logging branches in two places. A small helper (package-local) would keep them consistent:

// package-local helper somewhere appropriate
func isContextExit(err error) bool {
    return errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded)
}

Then:

if err := w(ctx); err != nil {
    if !isContextExit(err) {
        ll.Error("Error watching execution config", zap.Error(err))
    } else {
        ll.Debug("Watcher context cancelled, shutting down")
    }
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9d6aabb and 7b1aec0.

📒 Files selected for processing (4)
  • docker-compose.yml (1 hunks)
  • router/cmd/main.go (2 hunks)
  • router/core/router.go (1 hunks)
  • router/debug.config.yaml (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
router/cmd/main.go (1)
router/pkg/watcher/watcher.go (2)
  • New (20-101)
  • Options (12-18)
⏰ 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). (11)
  • GitHub Check: build-router
  • GitHub Check: build_push_image (nonroot)
  • GitHub Check: integration_test (./telemetry)
  • GitHub Check: image_scan (nonroot)
  • GitHub Check: image_scan
  • GitHub Check: integration_test (./events)
  • GitHub Check: build_push_image
  • GitHub Check: integration_test (./. ./fuzzquery ./lifecycle ./modules)
  • GitHub Check: build_test
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
router/debug.config.yaml (1)

8-11: WatchInterval default is non-zero (1s); no action needed

The ExecutionConfigFile struct in router/pkg/config/config.go declares a default WatchInterval of 1 second via its envDefault:"1s" tag, and the JSON defaults file (router/pkg/config/testdata/config_defaults.json) sets "WatchInterval": 1000000000 (nanoseconds) for the same field. Since watch_interval defaults to 1s, watcher.New will receive a positive interval and will not error out at startup—no explicit override is required in router/debug.config.yaml.

• router/pkg/config/config.go:819–822 – WatchInterval time.Duration \yaml:"watch_interval,omitempty" envDefault:"1s"` • router/pkg/config/testdata/config_defaults.json:438–441 –"WatchInterval": 1000000000`

docker-compose.yml (1)

191-191: Nice: CDN auth JWT can now come from .env with a sane fallback

Good usability improvement for local/dev setups.

router/cmd/main.go (1)

186-195: Watcher construction/readability: LGTM

Variable rename and logger scoping are clear. Callback logs and triggers rs.Reload() only once per stable tick via watcher package, which aligns with intended behavior.

Copy link
Copy Markdown
Contributor

@StarpTech StarpTech left a comment

Choose a reason for hiding this comment

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

LGTM

@endigma endigma merged commit 52804d3 into main Aug 26, 2025
45 of 48 checks passed
@endigma endigma deleted the jesse/eng-7975-watcher-context-cancel-ignore branch August 26, 2025 11:14
@Noroth Noroth mentioned this pull request Sep 30, 2025
5 tasks
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.

2 participants