Skip to content

Goroutine leak in Crontab — no Stop/Close mechanism #3211

@NitinKumar004

Description

@NitinKumar004

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

  1. Add a done chan struct{} field to Crontab.
  2. Replace the range loop with a select on ticker.C and done.
  3. Add a Stop() method that calls ticker.Stop() and closes done.

File

pkg/gofr/cron.go:62-78

Metadata

Metadata

Assignees

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