Description
Crontab in pkg/gofr/cron.go has no Stop() or Close() method. The goroutine spawned in NewCron() (lines 71-75) runs forever with no way to terminate it.
go func() {
for t := range c.ticker.C {
c.runScheduled(t)
}
}()
time.Ticker channels are never closed (even after ticker.Stop()), so range c.ticker.C blocks indefinitely. Without a done channel and select, this goroutine leaks on shutdown.
Impact
- Prevents graceful shutdown — the goroutine and ticker are never cleaned up.
- Every
NewCron() call creates an unstoppable goroutine.
Suggested Fix
- Add a
done chan struct{} field to Crontab.
- Replace the
range loop with a select on ticker.C and done.
- Add a
Stop() method that calls ticker.Stop() and closes done.
File
pkg/gofr/cron.go:62-78
Description
Crontabinpkg/gofr/cron.gohas noStop()orClose()method. The goroutine spawned inNewCron()(lines 71-75) runs forever with no way to terminate it.time.Tickerchannels are never closed (even afterticker.Stop()), sorange c.ticker.Cblocks indefinitely. Without adonechannel andselect, this goroutine leaks on shutdown.Impact
NewCron()call creates an unstoppable goroutine.Suggested Fix
done chan struct{}field toCrontab.rangeloop with aselectonticker.Canddone.Stop()method that callsticker.Stop()and closesdone.File
pkg/gofr/cron.go:62-78