fix(chromium): waitForSelector and waitForExpression poll indefinitely when the main page returns a bad HTTP status (e.g., 500)

This commit is contained in:
Julien Neuhart
2026-03-27 17:32:27 +01:00
parent 3a78b89c97
commit 0b33be17a4
2 changed files with 56 additions and 30 deletions

View File

@@ -168,6 +168,7 @@ type eventResponseReceivedOptions struct {
ignoreResourceHttpStatusDomains []string
invalidResourceHttpStatusCode *error
invalidResourceHttpStatusCodeMu *sync.RWMutex
cancelOnMainPageError context.CancelFunc
}
// listenForEventResponseReceived listens for an invalid HTTP status code
@@ -206,6 +207,14 @@ func listenForEventResponseReceived(
defer options.invalidHttpStatusCodeMu.Unlock()
*options.invalidHttpStatusCode = fmt.Errorf("%d: %s", ev.Response.Status, ev.Response.StatusText)
// Cancel the task context so that any in-flight wait
// operations (waitForSelector, waitForExpression, etc.)
// abort immediately instead of polling until timeout.
// See https://github.com/gotenberg/gotenberg/issues/1492.
if options.cancelOnMainPageError != nil {
options.cancelOnMainPageError()
}
}
return
@@ -309,6 +318,7 @@ type eventLoadingFailedOptions struct {
loadingFailedMu *sync.RWMutex
resourceLoadingFailed *error
resourceLoadingFailedMu *sync.RWMutex
cancelOnMainPageError context.CancelFunc
}
// listenForEventLoadingFailed listens for an event indicating that the main
@@ -353,6 +363,13 @@ func listenForEventLoadingFailed(ctx context.Context, logger *slog.Logger, optio
*options.loadingFailed = fmt.Errorf("%s", ev.ErrorText)
// Cancel the task context so that any in-flight wait
// operations abort immediately.
// See https://github.com/gotenberg/gotenberg/issues/1492.
if options.cancelOnMainPageError != nil {
options.cancelOnMainPageError()
}
return
}