Skip to content

Commit

Permalink
Fix bug when trying to load when there are pending failures.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
TheModMaker authored and joeyparrish committed Jun 12, 2017
1 parent 89699ae commit dcc8990
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/util/cancelable_chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
23 changes: 23 additions & 0 deletions test/util/cancelable_chain_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit dcc8990

Please sign in to comment.