Two parallel media key sessions with the same data not handled properly

Number:rdar://FB7562024 Date Originated:Feb 3, 2020
Status:Open Resolved:
Product:Safari Product Version:13.0.4
Classification:Incorrect/Unexpected Behavior Reproducible:YES
We're trying to play FairPlay protected HLS VOD stream that has a video track encrypted with dedicated key and 2 audio tracks encrypted with the same key. 
The native player on Safari thus issues 3 consecutive webkitneedkey events. 
Each event causes that our SDK does following (rough timeline of events): 
(1) create a media key session 
(2) get license request message from the session 
(3) fetch the license 
(4) update the session with the keys 
To create a media session one needs the init data which are passed along with the webkitneedkey event. 
For the audio tracks the init data are exactly the same which results in creating the "same" session twice and this seems to be problematic - duplicated/twin session sometimes throw an error which will lead the SDK to fail and sometimes there is just no errors and everything runs smoothly.

Steps to reproduce:
1. Prepare a content with a video track encrypted with one key and multiple audio tracks encrypted with the 2nd key (the same key for all audio tracks)
2. Wait for webkitneedkey events and on each occurrence create a media key session

Expected results:
Each media key session is created correctly and there is no error

Actual results:
In cca 50% of the attempts there is an error when trying to create media key session (we couldn't find a pattern)


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!