Skip to content

Unsafe key session removal. Regression since 4.7.2 #4430

@alexhmit

Description

@alexhmit
Environment
  • Link to playable MPD file: Any MPD containing DRM
  • Dash.js version: 4.7.2 or later
  • Browser name/version: WebKit
  • OS name/version: OEM
Steps to reproduce

This behavior is not stable. May or may not occur on a particular system. Please review the code change at https://github.com/Dash-Industry-Forum/dash.js/pull/4239/files#diff-8260cad47ef106d2b2ff4036c1c72af9333181ac995f57bdb92af5c8c91b86b7. This was introduced by PR #4239.

Priori to 4.7.2 the key session were removed in the following way:

for (let i = 0; i < sessions.length; i++) {
            session = sessions[i];
            if (!session.getUsable()) {
                _closeKeySessionInternal(session).catch(function () {
                    removeSession(session);
                });
            }
        }

removeSession is called in catch() only. This was changed to

                _closeKeySessionInternal(session)
                removeSession(session);

This will call removeSession unconditionally and NOT waiting for the resolution of _closeKeySessionInternal(). This can cause incoherence in underlying session object removal and session close() calls.

Maybe a better way is something like

_closeKeySessionInternal(session).finally(function () {
                    removeSession(session);
                });

This removes session when the promise resolves without error as well.

Observed behavior

On some systems this problematic code can lead to memory corruption and/or leak.

Console output

No useful logging for this since it is causing native area memory issues. I believe code review should be sufficient.

Expected behavior

Media key sessions removed correctly and resources reclaimed.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions