Skip to content

Cleanup context handling#758

Merged
ensonic merged 1 commit into
mainfrom
ensonic/context
Jun 26, 2026
Merged

Cleanup context handling#758
ensonic merged 1 commit into
mainfrom
ensonic/context

Conversation

@ensonic

@ensonic ensonic commented Jun 26, 2026

Copy link
Copy Markdown
Contributor
  1. Modernized Graceful Shutdown: Updated all entry-point main.go files to use os/signal.NotifyContext. This provides a base context that is automatically cancelled upon receiving termination signals (SIGINT/SIGTERM), allowing for graceful cleanup of all downstream components.
    • Updated: setup-dev, setup-robot, token-vendor, cr-syncer, http-relay-client, metadata-server, and gcr-credential-refresher.
  2. Context Propagation in Controllers: Refactored the Kubernetes controllers (chart-assignment-controller and app-rollout-controller) to use signals.SetupSignalHandler() for their base context, which is then passed down to reconcilers and background release managers.
  3. Refactored Library Functions: Updated configutil.ReadConfig and Synk.Init to accept a context.Context as their first parameter. This ensures that these long-running or network-dependent operations can be cancelled by their callers.
  4. Eliminated Deprecated Contexts: Replaced the obsolete golang.org/x/net/context with the standard library's context package in cr-syncer.
  5. Audit of context.TODO() and context.Background():
    • Confirmed that context.TODO() is not used (only in generated code).
    • Reduced the usage of context.Background() in production code, replacing it with passed-down contexts to ensure proper cancellation propagation.
  6. Cleanup of tests to use t.Context()

@ensonic ensonic requested a review from csieber June 26, 2026 12:53
@ensonic

ensonic commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Sorry for the large PR, the majority is using t.Context() in tests though.

@ensonic ensonic marked this pull request as draft June 26, 2026 12:54
@ensonic ensonic marked this pull request as ready for review June 26, 2026 13:00
Comment thread src/go/cmd/metadata-server/main.go
1. Modernized Graceful Shutdown: Updated all entry-point main.go files to use os/signal.NotifyContext. This provides a base context that is automatically cancelled upon receiving termination signals (SIGINT/SIGTERM), allowing for graceful cleanup of all
   downstream components.
   - Updated: setup-dev, setup-robot, token-vendor, cr-syncer, http-relay-client, metadata-server, and gcr-credential-refresher.
2. Context Propagation in Controllers: Refactored the Kubernetes controllers (chart-assignment-controller and app-rollout-controller) to use signals.SetupSignalHandler() for their base context, which is then passed down to reconcilers and background
   release managers.
3. Refactored Library Functions: Updated configutil.ReadConfig and Synk.Init to accept a context.Context as their first parameter. This ensures that these long-running or network-dependent operations can be cancelled by their callers.
4. Eliminated Deprecated Contexts: Replaced the obsolete golang.org/x/net/context with the standard library's context package in cr-syncer.
5. Audit of context.TODO() and context.Background():
   - Confirmed that context.TODO() is not used (only in generated code).
   - Reduced the usage of context.Background() in production code, replacing it with passed-down contexts to ensure proper cancellation propagation.
6. Cleanup of tests to use t.Context()
@ensonic ensonic merged commit 211e8fc into main Jun 26, 2026
7 checks passed
@ensonic ensonic deleted the ensonic/context branch June 26, 2026 16:35
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.

2 participants