#9661·jaeger

[Bug]: es-rollover: no cancellable context reaches ES calls Action.Do() has no context param

Author: Atul-KoundalCreated Sep 27, 2026Updated Sep 27, 2026
Labelsbug

What happened?

The es-rollover CLI (init, rollover, lookback subcommands) has no cancellable context anywhere in its call chain, so a slow or stuck Elasticsearch cluster can't be interrupted by the operator.

Tracing the context flow in cmd/es-rollover:

  • The Action interface in cmd/es-rollover/app/actions.go is Do() error : it takes no context.Context parameter.

  • Because of that, each implementation fabricates its own root context internally instead of receiving one:

    • cmd/es-rollover/app/rollover/action.go:23
    • cmd/es-rollover/app/init/action.go:24
    • cmd/es-rollover/app/lookback/action.go:32

    all do ctx := context.TODO().

  • ExecuteAction() (same file as the interface) already builds a context.Background() for the ES client constructor, but has no way to hand it to action.Do() since the interface doesn't accept one.

  • In main.go, all three RunE closures discard the cobra command (func(_ *cobra.Command, ...)), and main() calls rootCmd.Execute() rather than rootCmd.ExecuteContext(ctx).

So even a Ctrl+C during a long-running rollover against a struggling cluster has no way to propagate down to the in-flight HTTP calls.

Steps to reproduce

This is a code-inspection finding rather than a runtime repro:

  1. grep for context.TODO() under cmd/es-rollover/ : it appears in all three action.go files.
  2. Check the Action interface in cmd/es-rollover/app/actions.go : Do() error has no context parameter, so there's no way for a caller to pass one in even if it wanted to.
  3. Check main.go : all three RunE closures use func(_ *cobra.Command, args []string), discarding the command, and main() calls rootCmd.Execute() instead of rootCmd.ExecuteContext().

Expected behavior

Do(ctx) should accept a context.Context, threaded through from ExecuteAction (which already constructs one), which is in turn threaded from a cancellable context in main() , e.g. via signal.NotifyContext(context.Background(), os.Interrupt) passed to rootCmd.ExecuteContext(). That way an interrupt or a future deadline actually reaches the underlying esclient.IndexAPI calls instead of being silently swallowed by context.TODO().

Relevant log output

bash
N/A  not a runtime failure, no logs to attach.

Screenshot

No response

Additional context

Proposed fix, roughly:

  1. Add a context.Context parameter to Action.Do(ctx) and thread it through ExecuteAction.
  2. Replace the three context.TODO() call sites with the passed-in context.
  3. In main.go, stop discarding the cobra command, use cmd.Context(), and switch rootCmd.Execute() to rootCmd.ExecuteContext() with a signal-derived context.

Testing: existing unit tests for rollover/init/lookback already pass a ctx into the unexported helper methods, so updating Do(ctx) is mechanical. Add a test asserting Do(ctx) propagates the given context down to the mocked esclient.IndexAPI calls (e.g. via mock.MatchedBy on the context) instead of always using a fresh background context.

Happy to submit a PR for this.

Jaeger backend version

No response

SDK

No response

Pipeline

No response

Stogage backend

No response

Operating system

No response

Deployment model

No response

Deployment configs

bash