polimediaupv / paella-core

Paella Player core library
Educational Community License v2.0
20 stars 15 forks source link

Race condition between this.streamData being set and this._validContentIds being set, uncaught exception #339

Closed karendolan closed 11 months ago

karendolan commented 11 months ago

There is a delay between this._streamData = streamData and this._validContentIds = getValidContentIds(this.player, streamData); https://github.com/polimediaupv/paella-core/blob/main/src/js/core/VideoContainer.js#L378-L381

So the protection in this check doesn't catch that _validContentIds is still undefined.

        if (!this.streamData) {
            // The stream data is not loaded. This can happen if the player is in MANIFEST_LOADED state
            // and the player container is resized
            return;
        }

returns true, but this._validContentIds a few lines down is still undefined, and throws an uncaught exception when this._validContentIds.indexOf is called on it. https://github.com/polimediaupv/paella-core/blob/main/src/js/core/VideoContainer.js#L378-L381

karendolan commented 11 months ago

It would help to initialize the Video container with _validContentIds = []; [EDIT] That didn't help it just pushes the issue to another error further down, still related to the race condition.

ferserc1 commented 11 months ago

I don't think I would have ever detected this issue. Thank you!

The problem can be easily fixed by checking the state of the player, instead of checking the value of this.streamData. I will probably have to change something else, since the updateLayout() function is also called at the end of the video loading() function, but before the state changes. I think that it can fix it by adding some kind of private parameter to the setLayout() function so that it does not check the state only in this case.