Skip to content

REMOTE_LOG_FETCH_INTERVAL=0 or negative crashes the app with "non-positive interval for NewTicker" #4419

Description

@NitinKumar004

Summary

With REMOTE_LOG_URL set, setting REMOTE_LOG_FETCH_INTERVAL=0 (or any negative value) crashes the application right after startup:

panic: non-positive interval for NewTicker

The panic happens in a background goroutine, so nothing can recover it and the process exits. A user who sets 0 intending "fetch once" or "no polling" brings the service down on every start.

Reproduction

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
	w.Write([]byte(`{"data":{"serviceName":"x","logLevel":"DEBUG"}}`))
}))

_ = container.NewContainer(config.NewMockConfig(map[string]string{
	"REMOTE_LOG_URL":            srv.URL,
	"REMOTE_LOG_FETCH_INTERVAL": "0",
}))
time.Sleep(2 * time.Second)
panic: non-positive interval for NewTicker
gofr.dev/pkg/gofr/logging/remotelogger.(*remoteLogger).UpdateLogLevel
	pkg/gofr/logging/remotelogger/dynamic_level_logger.go:316
created by gofr.dev/pkg/gofr/logging/remotelogger.New
	pkg/gofr/logging/remotelogger/dynamic_level_logger.go:163

Root cause

  • pkg/gofr/container/container.go:122-125 only falls back to the 15s default when strconv.Atoi fails. 0 and negative numbers parse fine, so they are passed on as they are.
  • remotelogger.New starts UpdateLogLevel in a goroutine (line 163), which calls time.NewTicker(r.levelFetchInterval) (line 316). time.NewTicker panics on a non-positive duration.

Impact

  • One config value crashes the service on every start. The stack trace points at the remote logger, not at the env var.
  • There is already an "invalid value for REMOTE_LOG_FETCH_INTERVAL" error message (line 131), but it is never reached for these values.

Suggested fix

  • In the container, treat levelFetchConfig <= 0 the same as a parse error: fall back to 15 and log the existing error.
  • Add a defensive guard in remotelogger.New too.
  • Alternatively, define 0 as "fetch once, no polling" and document it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions