diff --git a/src/core/chunked_stream.js b/src/core/chunked_stream.js index c764c7181..a4ba183b5 100644 --- a/src/core/chunked_stream.js +++ b/src/core/chunked_stream.js @@ -410,18 +410,24 @@ class ChunkedStreamManager { requestIds.push(requestId); } - if (!chunksToRequest.length) { - return capability.promise; + if (chunksToRequest.length > 0) { + const groupedChunksToRequest = this.groupChunks(chunksToRequest); + for (const groupedChunk of groupedChunksToRequest) { + const begin = groupedChunk.beginChunk * this.chunkSize; + const end = Math.min( + groupedChunk.endChunk * this.chunkSize, + this.length + ); + this.sendRequest(begin, end); + } } - const groupedChunksToRequest = this.groupChunks(chunksToRequest); - for (const groupedChunk of groupedChunksToRequest) { - const begin = groupedChunk.beginChunk * this.chunkSize; - const end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length); - this.sendRequest(begin, end); - } - - return capability.promise; + return capability.promise.catch(reason => { + if (this.aborted) { + return; // Ignoring any pending requests after abort. + } + throw reason; + }); } getStream() { diff --git a/src/display/api.js b/src/display/api.js index 140dafc49..bd48ca824 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -2048,6 +2048,13 @@ class WorkerTransport { sink.onCancel = reason => { this._fullReader.cancel(reason); + + sink.ready.catch(readyReason => { + if (this.destroyed) { + return; // Ignore any pending requests if the worker was terminated. + } + throw readyReason; + }); }; }); @@ -2127,6 +2134,13 @@ class WorkerTransport { sink.onCancel = reason => { rangeReader.cancel(reason); + + sink.ready.catch(readyReason => { + if (this.destroyed) { + return; // Ignore any pending requests if the worker was terminated. + } + throw readyReason; + }); }; });