-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect premature worker load error #7107
Conversation
This PR is required for Firefox 45+, because |
@@ -1302,11 +1302,25 @@ var PDFWorker = (function PDFWorkerClosure() { | |||
// https://bugzilla.mozilla.org/show_bug.cgi?id=683280 | |||
var worker = new Worker(workerSrc); | |||
var messageHandler = new MessageHandler('main', 'worker', worker); | |||
var terminateEarly = function() { | |||
this._readyCapability.reject(new Error('Worker was destroyed')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this._setupFakeWorker();
is needed here to call the fallback function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done; I've overwritten the previous commit, with the following changes (see PR for full change set).
@@ -1303,15 +1303,22 @@ var PDFWorker = (function PDFWorkerClosure() {
var worker = new Worker(workerSrc);
var messageHandler = new MessageHandler('main', 'worker', worker);
var terminateEarly = function() {
- this._readyCapability.reject(new Error('Worker was destroyed'));
- messageHandler.destroy();
worker.removeEventListener('error', onWorkerError);
+ messageHandler.destroy();
worker.terminate();
+ if (this.destroyed) {
+ this._readyCapability.reject(new Error('Worker was destroyed'));
+ } else {
+ // Fall back to fake worker if the termination is caused by an
+ // error (e.g. NetworkError / SecurityError).
+ this._setupFakeWorker();
+ }
}.bind(this);
var onWorkerError = function(event) {
- if (!event.message && !this.destroyed && !this._webWorker) {
- // Worker failed to initialize due to a load error.
+ if (!this._webWorker) {
+ // Worker failed to initialize due to an error. Clean up and fall
+ // back to the fake worker.
terminateEarly();
}
}.bind(this);
If I'm understanding the bugs correctly, this issue only affect custom deployments of PDF.js, and not the version built-in to Firefox!? |
I think the build-in version in Firefox is NOT affected. |
Fall back to a fake worker if the worker fails to load or initialize, e.g. due to a network error, a security error or simply a script error.
Looks good. /botio test |
From: Bot.io (Windows)ReceivedCommand cmd_test from @yurydelendik received. Current queue size: 0 Live output at: http://107.22.172.223:8877/f90f21d7f244cd5/output.txt |
From: Bot.io (Linux)ReceivedCommand cmd_test from @yurydelendik received. Current queue size: 0 Live output at: http://107.21.233.14:8877/75c21ae65928459/output.txt |
From: Bot.io (Windows)SuccessFull output at http://107.22.172.223:8877/f90f21d7f244cd5/output.txt Total script time: 20.08 mins
|
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/75c21ae65928459/output.txt Total script time: 22.68 mins
|
Thank you for the patch. |
Awesome, thank you! |
@yurydelendik Any ETA on PDF.js v1.4.187? |
@kyoshino you can download library from the mozilla/pdfjs-dist repo. the viewer package will be available as soon we are release next beta. You can build it yourself using |
Oh I see, thanks. I'll mention it in my site compat doc. |
Rejects the ready promise when the worker fails to load, e.g. due to network errors.