Skip to content

Commit

Permalink
fix(preload): Fix load interruption (#6271)
Browse files Browse the repository at this point in the history
Interrupting load() was causing two concurrent sets of load() operations
to happen at once, which led the asset URI for the second operation to
be overwritten by the first.

This was exposed by a test failure on Safari. There is nothing special
about Safari, but the timing happened to work out such that the
concurrent load() calls would intefere with each other.

This fixes the issue by acquiring the mutex in load() for the
preloadManager.start() operation.

This issue did not affect any releases.

Closes #6225
  • Loading branch information
joeyparrish committed Feb 21, 2024
1 parent ddc2499 commit d795a00
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/player.js
Expand Up @@ -1440,11 +1440,13 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
// "preload" here without prefetch.
// That way, both a preload and normal load can follow the same code
// paths.
// NOTE: await preloadInner_ can be outside the mutex because it should
// not mutate "this".
preloadManager = await this.preloadInner_(
assetUri, startTime, mimeType, /* standardLoad= */ true);
if (preloadManager) {
preloadManager.setEventHandoffTarget(this);
await preloadManager.start();
await mutexWrapOperation(() => preloadManager.start(), 'preload');
}
} else {
// Hook up events, so any events emitted by the preloadManager will
Expand Down
2 changes: 2 additions & 0 deletions test/player_load_graph_integration.js
Expand Up @@ -756,6 +756,7 @@ describe('Player Load Graph', () => {
'manifest-parser',
'manifest',
'drm-engine',
// Excludes 'unload'.
]);

/** @type {!Set.<string>} */
Expand All @@ -774,6 +775,7 @@ describe('Player Load Graph', () => {
await player.attach(video);
player.load('test:sintel').catch(() => {});
} else {
goog.asserts.assert(state == 'unload', 'Unrecognized testing state!');
await player.attach(video);
await player.load('test:sintel');
player.unload().catch(() => {});
Expand Down

0 comments on commit d795a00

Please sign in to comment.