FreeTubeApp / FreeTube

An Open Source YouTube app for privacy
https://freetubeapp.io/
GNU Affero General Public License v3.0
13.63k stars 861 forks source link

Better player error handling #6180

Closed absidue closed 1 day ago

absidue commented 4 days ago

Better player error handling

Pull Request Type

Related issue

closes #6028 closes #6198 Probably also #6074

Description

This pull request makes various changes to the player error handling.

  1. When an error happens that we consider to be critical enough to trigger a format fallback, we now ignore any other errors that occur because of the previous format, as the legacy formats can throw multiple errors in a row, which ends up interrupting the fallback to the audio formats, which then throws an error because it got interrupted and we end up in an extremely quick loop piling up thousands of errors in just a few seconds as it attempts to fallback and keeps interrupting itself. This results in it being impossible to do anything with the window as it is stuck in that endless loop.
  2. We now fully unload the previous format during a format switch before loading the next one, this helps with number 1 as we can separate which errors happened when and helps slow down the fallbacks and errors, giving the user more time to leave the page if they do end up in an error loop
  3. We now ignore errors when destroying the player, while I haven't found any direct problems caused by that, it's just a precaution to hopefully allow the user to always leave the watch page.
  4. When an error happens in the response filter, shaka-player throws a RESPONSE_FILTER_ERROR which is a wrapper around the original error, previously we weren't unwrapping the nested errors so we didn't actually log or look at the original error. This can happen if the user is using a blocked IP and uses an Invidious instance far away from them without having Proxy Videos Through Invidious enabled. In that scenario YouTube will redirect you multiple times to give you a googlevideo server that is closer to your IP address and the last redirect will get a 403 from YouTube because of your blocked IP, this then results in RESPONSE_FILTER_ERROR -> RESPONSE_FILTER_ERROR -> RESPONSE_FILTER_ERROR -> BAD_HTTP_STATUS error chain. We have handling for BAD_HTTP_STATUS errors but we weren't getting to that before because we weren't looking at the original error.

Testing

  1. Check that changing formats still works
  2. If you have access to a blocked IP address: Use the Invidious API with Proxy Videos Through Invidious disabled and check that the 403 IP block message shows up, instead of it switching formats.

Desktop

efb4f5ff-1298-471a-8973-3d47447115dc commented 4 days ago
  1. Check that changing formats still works

Error :(

https://github.com/user-attachments/assets/f8be7911-fada-44cc-a547-00fea7910648

  1. If you have access to a blocked IP address: Use the Invidious API with Proxy Videos Through Invidious disabled and check that the 403 IP block message shows up, instead of it switching formats.

Looks to be working correctly

https://github.com/user-attachments/assets/e86577b6-16a2-4132-85c7-3c4bb8cd4487

absidue commented 2 days ago

Should be fixed now.

efb4f5ff-1298-471a-8973-3d47447115dc commented 2 days ago

still doesnt work :(

https://github.com/user-attachments/assets/ea5710ec-250a-4049-99ed-1f848202f305