added default panic-recover handling for the cron jobs

This commit is contained in:
Gani Georgiev
2026-05-31 10:34:27 +03:00
parent f3ae7731d4
commit 40d2849aa6
3 changed files with 6 additions and 2 deletions
+2
View File
@@ -4,6 +4,8 @@
- Return the hidden record data fields for superusers realtime subscribers ([#7721](https://github.com/pocketbase/pocketbase/issues/7721)). - Return the hidden record data fields for superusers realtime subscribers ([#7721](https://github.com/pocketbase/pocketbase/issues/7721)).
- Added default panic-recover handling for the cron jobs to avoid terminating the application on panic.
## v0.39.0 ## v0.39.0
+3 -1
View File
@@ -14,6 +14,8 @@ import (
"slices" "slices"
"sync" "sync"
"time" "time"
"github.com/pocketbase/pocketbase/tools/routine"
) )
// Cron is a crontab-like struct for tasks/jobs scheduling. // Cron is a crontab-like struct for tasks/jobs scheduling.
@@ -222,7 +224,7 @@ func (c *Cron) runDue(t time.Time) {
for _, j := range c.jobs { for _, j := range c.jobs {
if j.schedule.IsDue(moment) { if j.schedule.IsDue(moment) {
go j.Run() routine.FireAndForget(j.Run)
} }
} }
} }
+1 -1
View File
@@ -22,7 +22,7 @@ func FireAndForget(f func(), wg ...*sync.WaitGroup) {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
log.Println("RECOVERED FROM PANIC (safe to ignore):", err) log.Println("[FireAndForget] RECOVERED FROM PANIC:", err)
stack := make([]byte, 2<<10) // 2 KB stack := make([]byte, 2<<10) // 2 KB
length := runtime.Stack(stack, false) length := runtime.Stack(stack, false)