Skip to content

Commit 9677798

Browse files
committed
Fix Worker was terminated error when loading is cancelled
Fixes #11595, where cancelling loading with `loadingTask.destroy()` before it finishes throws a `Worker was terminated` error that CANNOT be caught. When worker is terminated, an error is thrown here: https://github.com/mozilla/pdf.js/blob/6c746260a98766b8ece27018d2c48436cfcafa24/src/core/worker.js#L374 Then `onFailure` runs, in which we throw again via `ensureNotTerminated()`. However, this second error is never caught (and cannot be), resulting in console spam. There is no need to throw any additional errors since the termination is already reported [here](https://github.com/mozilla/pdf.js/blob/6c746260a98766b8ece27018d2c48436cfcafa24/src/core/worker.js#L371-L373), and `onFailure` is supposed to handle errors, not throw them.
1 parent 6c74626 commit 9677798

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/core/worker.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ class WorkerMessageHandler {
319319
}
320320

321321
function onFailure(ex) {
322-
ensureNotTerminated();
322+
if (terminated) {
323+
return;
324+
}
323325

324326
if (ex instanceof PasswordException) {
325327
const task = new WorkerTask(`PasswordException: response ${ex.code}`);

0 commit comments

Comments
 (0)