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.
Summary
With
REMOTE_LOG_URLset, settingREMOTE_LOG_FETCH_INTERVAL=0(or any negative value) crashes the application right after startup:The panic happens in a background goroutine, so nothing can recover it and the process exits. A user who sets
0intending "fetch once" or "no polling" brings the service down on every start.Reproduction
Root cause
pkg/gofr/container/container.go:122-125only falls back to the 15s default whenstrconv.Atoifails.0and negative numbers parse fine, so they are passed on as they are.remotelogger.NewstartsUpdateLogLevelin a goroutine (line 163), which callstime.NewTicker(r.levelFetchInterval)(line 316).time.NewTickerpanics on a non-positive duration.Impact
Suggested fix
levelFetchConfig <= 0the same as a parse error: fall back to 15 and log the existing error.remotelogger.Newtoo.0as "fetch once, no polling" and document it.