Skip to content

Commit ed8ac48

Browse files
fix: improve background-worker boot-failure logs
Background workers inherited the HTTP-worker wording which mentioned frankenphp_handle_request — that function doesn't apply to bg workers. The ready signal for a bg worker is frankenphp_set_vars. - startupFailChan error: "background worker %s has not reached frankenphp_set_vars()" - Warn log (watcher): "(watcher enabled) background worker has not reached frankenphp_set_vars()" - Warn log (normal): "background worker boot failed, restarting" The log now also carries exit_status and, when captured, the last PHP error message from bootFailureInfo. Tailing the FrankenPHP log at Warn level is enough to see what went wrong without reading the PHP error log separately.
1 parent 82f7a0e commit ed8ac48

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

threadbackgroundworker.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,24 @@ func (handler *backgroundWorkerThread) afterScriptExecution(exitStatus int) {
206206
}
207207

208208
if worker.maxConsecutiveFailures >= 0 && startupFailChan != nil && !watcherIsEnabled && handler.failureCount >= worker.maxConsecutiveFailures {
209-
startupFailChan <- fmt.Errorf("too many consecutive failures: worker %s has not reached frankenphp_handle_request()", worker.fileName)
209+
startupFailChan <- fmt.Errorf("too many consecutive failures: background worker %s has not reached frankenphp_set_vars()", worker.fileName)
210210
handler.thread.state.Set(state.ShuttingDown)
211211
return
212212
}
213213

214+
attrs := []slog.Attr{slog.String("worker", worker.name), slog.Int("thread", handler.thread.threadIndex), slog.Int("failures", handler.failureCount), slog.Int("exit_status", exitStatus)}
215+
if worker.backgroundWorker != nil {
216+
if info := worker.backgroundWorker.bootFailure.Load(); info != nil && info.phpError != "" {
217+
attrs = append(attrs, slog.String("error", info.phpError))
218+
}
219+
}
214220
if watcherIsEnabled {
215221
if globalLogger.Enabled(globalCtx, slog.LevelWarn) {
216-
globalLogger.LogAttrs(globalCtx, slog.LevelWarn, "(watcher enabled) worker script has not reached frankenphp_handle_request()", slog.String("worker", worker.name), slog.Int("thread", handler.thread.threadIndex))
222+
globalLogger.LogAttrs(globalCtx, slog.LevelWarn, "(watcher enabled) background worker has not reached frankenphp_set_vars()", attrs...)
217223
}
218224
} else {
219225
if globalLogger.Enabled(globalCtx, slog.LevelWarn) {
220-
globalLogger.LogAttrs(globalCtx, slog.LevelWarn, "worker script has failed on restart", slog.String("worker", worker.name), slog.Int("thread", handler.thread.threadIndex), slog.Int("failures", handler.failureCount))
226+
globalLogger.LogAttrs(globalCtx, slog.LevelWarn, "background worker boot failed, restarting", attrs...)
221227
}
222228
}
223229

0 commit comments

Comments
 (0)