From dcc899088311063889dca86c5e7b5129825a900a Mon Sep 17 00:00:00 2001 From: Jacob Trimble Date: Wed, 7 Jun 2017 11:32:11 -0700 Subject: [PATCH] Fix bug when trying to load when there are pending failures. If you attempt to load an asset and then the first load fails, then the second load will hang forever. This was caused by the second load trying to cancel the first, but the CancelableChain not handling this case. Closes #782 Change-Id: I79e201db44cbf47485e7221cc148bbfdde6276f7 --- lib/util/cancelable_chain.js | 5 +++++ test/util/cancelable_chain_unit.js | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/util/cancelable_chain.js b/lib/util/cancelable_chain.js index 8e73bcb6af..383f1ec877 100644 --- a/lib/util/cancelable_chain.js +++ b/lib/util/cancelable_chain.js @@ -93,6 +93,11 @@ shaka.util.CancelableChain.prototype.finalize = function() { return Promise.resolve(data); }.bind(this), function(error) { this.complete_ = true; + if (this.canceled_) { + this.onCancelComplete_(); + return Promise.reject(this.rejectionValue_); + } + return Promise.reject(error); }.bind(this)); } diff --git a/test/util/cancelable_chain_unit.js b/test/util/cancelable_chain_unit.js index 85ad04673b..09435963ec 100644 --- a/test/util/cancelable_chain_unit.js +++ b/test/util/cancelable_chain_unit.js @@ -159,6 +159,29 @@ describe('CancelableChain', function() { block.resolve(); }); + it('works even if stage is rejected after being canceled', function(done) { + var p = new shaka.util.PublicPromise(); + var finalComplete = false; + chain.then(function() { + return p; + }).finalize().then(fail).catch(function(err) { + finalComplete = true; + shaka.test.Util.expectToEqualError(cannedError, err); + }); + + chain.cancel(cannedError).catch(fail).then(function() { + // Delay so the catch block above can run. + return shaka.test.Util.delay(0.1); + }).then(function() { + expect(finalComplete).toBe(true); + done(); + }); + p.reject(new shaka.util.Error( + shaka.util.Error.Severity.CRITICAL, + shaka.util.Error.Category.MANIFEST, + shaka.util.Error.Code.UNABLE_TO_GUESS_MANIFEST_TYPE)); + }); + it('resolves even after the finalized chain is resolved', function(done) { var stageComplete = false; var finalComplete = false;