Merge pull request #11034 from Snuffleupagus/cancel-with-AbortException
Ensure that `ReadableStream`s are cancelled with actual Errors
This commit is contained in:
commit
9c8fe3142a
@ -567,14 +567,13 @@ class ChunkedStreamManager {
|
|||||||
return Math.floor((end - 1) / this.chunkSize) + 1;
|
return Math.floor((end - 1) / this.chunkSize) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
abort() {
|
abort(reason) {
|
||||||
this.aborted = true;
|
this.aborted = true;
|
||||||
if (this.pdfNetworkStream) {
|
if (this.pdfNetworkStream) {
|
||||||
this.pdfNetworkStream.cancelAllRequests('abort');
|
this.pdfNetworkStream.cancelAllRequests(reason);
|
||||||
}
|
}
|
||||||
for (const requestId in this.promisesByRequest) {
|
for (const requestId in this.promisesByRequest) {
|
||||||
this.promisesByRequest[requestId].reject(
|
this.promisesByRequest[requestId].reject(reason);
|
||||||
new Error('Request was aborted'));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ class BasePdfManager {
|
|||||||
this._password = password;
|
this._password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
terminate() {
|
terminate(reason) {
|
||||||
unreachable('Abstract method `terminate` called');
|
unreachable('Abstract method `terminate` called');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,7 +134,7 @@ class LocalPdfManager extends BasePdfManager {
|
|||||||
return this._loadedStreamPromise;
|
return this._loadedStreamPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
terminate() {}
|
terminate(reason) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NetworkPdfManager extends BasePdfManager {
|
class NetworkPdfManager extends BasePdfManager {
|
||||||
@ -188,8 +188,8 @@ class NetworkPdfManager extends BasePdfManager {
|
|||||||
return this.streamManager.onLoadedStream();
|
return this.streamManager.onLoadedStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
terminate() {
|
terminate(reason) {
|
||||||
this.streamManager.abort();
|
this.streamManager.abort(reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,10 +14,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
arrayByteLength, arraysToBytes, createPromiseCapability, getVerbosityLevel,
|
AbortException, arrayByteLength, arraysToBytes, createPromiseCapability,
|
||||||
info, InvalidPDFException, MissingPDFException, PasswordException,
|
getVerbosityLevel, info, InvalidPDFException, MissingPDFException,
|
||||||
setVerbosityLevel, UnexpectedResponseException, UnknownErrorException,
|
PasswordException, setVerbosityLevel, UnexpectedResponseException,
|
||||||
UNSUPPORTED_FEATURES, VerbosityLevel, warn
|
UnknownErrorException, UNSUPPORTED_FEATURES, VerbosityLevel, warn
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import { clearPrimitiveCaches, Ref } from './primitives';
|
import { clearPrimitiveCaches, Ref } from './primitives';
|
||||||
import { LocalPdfManager, NetworkPdfManager } from './pdf_manager';
|
import { LocalPdfManager, NetworkPdfManager } from './pdf_manager';
|
||||||
@ -274,8 +274,8 @@ var WorkerMessageHandler = {
|
|||||||
cancelXHRs = null;
|
cancelXHRs = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
cancelXHRs = function () {
|
cancelXHRs = function(reason) {
|
||||||
pdfStream.cancelAllRequests('abort');
|
pdfStream.cancelAllRequests(reason);
|
||||||
};
|
};
|
||||||
|
|
||||||
return pdfManagerCapability.promise;
|
return pdfManagerCapability.promise;
|
||||||
@ -349,7 +349,7 @@ var WorkerMessageHandler = {
|
|||||||
if (terminated) {
|
if (terminated) {
|
||||||
// We were in a process of setting up the manager, but it got
|
// We were in a process of setting up the manager, but it got
|
||||||
// terminated in the middle.
|
// terminated in the middle.
|
||||||
newPdfManager.terminate();
|
newPdfManager.terminate(new AbortException('Worker was terminated.'));
|
||||||
throw new Error('Worker was terminated');
|
throw new Error('Worker was terminated');
|
||||||
}
|
}
|
||||||
pdfManager = newPdfManager;
|
pdfManager = newPdfManager;
|
||||||
@ -579,11 +579,11 @@ var WorkerMessageHandler = {
|
|||||||
handler.on('Terminate', function wphTerminate(data) {
|
handler.on('Terminate', function wphTerminate(data) {
|
||||||
terminated = true;
|
terminated = true;
|
||||||
if (pdfManager) {
|
if (pdfManager) {
|
||||||
pdfManager.terminate();
|
pdfManager.terminate(new AbortException('Worker was terminated.'));
|
||||||
pdfManager = null;
|
pdfManager = null;
|
||||||
}
|
}
|
||||||
if (cancelXHRs) {
|
if (cancelXHRs) {
|
||||||
cancelXHRs();
|
cancelXHRs(new AbortException('Worker was terminated.'));
|
||||||
}
|
}
|
||||||
clearPrimitiveCaches();
|
clearPrimitiveCaches();
|
||||||
|
|
||||||
|
@ -16,10 +16,11 @@
|
|||||||
/* eslint no-var: error */
|
/* eslint no-var: error */
|
||||||
|
|
||||||
import {
|
import {
|
||||||
assert, createPromiseCapability, getVerbosityLevel, info, InvalidPDFException,
|
AbortException, assert, createPromiseCapability, getVerbosityLevel, info,
|
||||||
isArrayBuffer, isSameOrigin, MissingPDFException, NativeImageDecoding,
|
InvalidPDFException, isArrayBuffer, isSameOrigin, MissingPDFException,
|
||||||
PasswordException, setVerbosityLevel, shadow, stringToBytes,
|
NativeImageDecoding, PasswordException, setVerbosityLevel, shadow,
|
||||||
UnexpectedResponseException, UnknownErrorException, unreachable, URL, warn
|
stringToBytes, UnexpectedResponseException, UnknownErrorException,
|
||||||
|
unreachable, URL, warn
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import {
|
import {
|
||||||
deprecated, DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer,
|
deprecated, DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer,
|
||||||
@ -1768,7 +1769,8 @@ class WorkerTransport {
|
|||||||
Promise.all(waitOn).then(() => {
|
Promise.all(waitOn).then(() => {
|
||||||
this.fontLoader.clear();
|
this.fontLoader.clear();
|
||||||
if (this._networkStream) {
|
if (this._networkStream) {
|
||||||
this._networkStream.cancelAllRequests();
|
this._networkStream.cancelAllRequests(
|
||||||
|
new AbortException('Worker was terminated.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.messageHandler) {
|
if (this.messageHandler) {
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
/* eslint no-var: error */
|
/* eslint no-var: error */
|
||||||
|
|
||||||
|
import { AbortException } from '../../src/shared/util';
|
||||||
import { PDFFetchStream } from '../../src/display/fetch_stream';
|
import { PDFFetchStream } from '../../src/display/fetch_stream';
|
||||||
|
|
||||||
describe('fetch_stream', function() {
|
describe('fetch_stream', function() {
|
||||||
@ -72,7 +73,7 @@ describe('fetch_stream', function() {
|
|||||||
isStreamingSupported = fullReader.isStreamingSupported;
|
isStreamingSupported = fullReader.isStreamingSupported;
|
||||||
isRangeSupported = fullReader.isRangeSupported;
|
isRangeSupported = fullReader.isRangeSupported;
|
||||||
// We shall be able to close full reader without any issue.
|
// We shall be able to close full reader without any issue.
|
||||||
fullReader.cancel(new Error('Don\'t need full reader'));
|
fullReader.cancel(new AbortException('Don\'t need fullReader.'));
|
||||||
fullReaderCancelled = true;
|
fullReaderCancelled = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { createPromiseCapability } from '../../src/shared/util';
|
import { AbortException, createPromiseCapability } from '../../src/shared/util';
|
||||||
import { LoopbackPort } from '../../src/display/api';
|
import { LoopbackPort } from '../../src/display/api';
|
||||||
import { MessageHandler } from '../../src/shared/message_handler';
|
import { MessageHandler } from '../../src/shared/message_handler';
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ describe('message_handler', function () {
|
|||||||
return sleep(10);
|
return sleep(10);
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
expect(log).toEqual('01p2');
|
expect(log).toEqual('01p2');
|
||||||
return reader.cancel();
|
return reader.cancel(new AbortException('reader cancelled.'));
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
expect(log).toEqual('01p2c4');
|
expect(log).toEqual('01p2c4');
|
||||||
done();
|
done();
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { AbortException } from '../../src/shared/util';
|
||||||
import { PDFNetworkStream } from '../../src/display/network';
|
import { PDFNetworkStream } from '../../src/display/network';
|
||||||
|
|
||||||
describe('network', function() {
|
describe('network', function() {
|
||||||
@ -79,7 +80,7 @@ describe('network', function() {
|
|||||||
isStreamingSupported = fullReader.isStreamingSupported;
|
isStreamingSupported = fullReader.isStreamingSupported;
|
||||||
isRangeSupported = fullReader.isRangeSupported;
|
isRangeSupported = fullReader.isRangeSupported;
|
||||||
// we shall be able to close the full reader without issues
|
// we shall be able to close the full reader without issues
|
||||||
fullReader.cancel('Don\'t need full reader');
|
fullReader.cancel(new AbortException('Don\'t need fullReader.'));
|
||||||
fullReaderCancelled = true;
|
fullReaderCancelled = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
/* globals __non_webpack_require__ */
|
/* globals __non_webpack_require__ */
|
||||||
|
|
||||||
import { assert } from '../../src/shared/util';
|
import { AbortException, assert } from '../../src/shared/util';
|
||||||
import isNodeJS from '../../src/shared/is_node';
|
import isNodeJS from '../../src/shared/is_node';
|
||||||
import { PDFNodeStream } from '../../src/display/node_stream';
|
import { PDFNodeStream } from '../../src/display/node_stream';
|
||||||
|
|
||||||
@ -167,14 +167,14 @@ describe('node_stream', function() {
|
|||||||
isStreamingSupported1 = fullReader1.isStreamingSupported;
|
isStreamingSupported1 = fullReader1.isStreamingSupported;
|
||||||
isRangeSupported1 = fullReader1.isRangeSupported;
|
isRangeSupported1 = fullReader1.isRangeSupported;
|
||||||
// we shall be able to close the full reader without issues
|
// we shall be able to close the full reader without issues
|
||||||
fullReader1.cancel('Don\'t need full reader');
|
fullReader1.cancel(new AbortException('Don\'t need fullReader1.'));
|
||||||
fullReaderCancelled1 = true;
|
fullReaderCancelled1 = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
let promise2 = fullReader2.headersReady.then(function () {
|
let promise2 = fullReader2.headersReady.then(function () {
|
||||||
isStreamingSupported2 = fullReader2.isStreamingSupported;
|
isStreamingSupported2 = fullReader2.isStreamingSupported;
|
||||||
isRangeSupported2 = fullReader2.isRangeSupported;
|
isRangeSupported2 = fullReader2.isRangeSupported;
|
||||||
fullReader2.cancel('Don\'t need full reader');
|
fullReader2.cancel(new AbortException('Don\'t need fullReader2.'));
|
||||||
fullReaderCancelled2 = true;
|
fullReaderCancelled2 = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user