From 23e0d764a0ab58645d7e5fc953f524a49126920e Mon Sep 17 00:00:00 2001 From: Theodore Abshire Date: Wed, 8 Sep 2021 17:20:00 -0700 Subject: [PATCH] fix(offline): Fix error when un-storing DRM asset The DRM engine, when asked to remove a session, would then remove it again when destroyed. This changes the DRM engine to no longer track removed sessions as active. Closes #3534 Change-Id: I2a3b99eb97e1d8f68282062c592a7cd35ffbe3cd --- lib/media/drm_engine.js | 1 + test/media/drm_engine_unit.js | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/media/drm_engine.js b/lib/media/drm_engine.js index 33755e9bea..200011c088 100644 --- a/lib/media/drm_engine.js +++ b/lib/media/drm_engine.js @@ -550,6 +550,7 @@ shaka.media.DrmEngine = class { tasks.push(session.remove()); await Promise.all(tasks); + this.activeSessions_.delete(session); } /** diff --git a/test/media/drm_engine_unit.js b/test/media/drm_engine_unit.js index 405979f227..707a2372c6 100644 --- a/test/media/drm_engine_unit.js +++ b/test/media/drm_engine_unit.js @@ -2285,6 +2285,19 @@ describe('DrmEngine', () => { await expectAsync(drmEngine.removeSession('abc')) .toBeRejectedWith(expected); }); + + // Regression test for #3534 + it('does not remove the same session again on destroy', async () => { + updatePromise.resolve(); + expect(session1.remove).not.toHaveBeenCalled(); + await drmEngine.removeSession('abc'); + expect(session1.remove).toHaveBeenCalled(); + session1.remove.calls.reset(); + await drmEngine.destroy(); + // The session should only be removed ONCE. If it's double-removed, it + // will make a (non-fatal) DOMException. + expect(session1.remove).not.toHaveBeenCalled(); + }); }); describe('expiration', () => {