Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Youtube plugin crashes on Ubuntu 22.04 #298

Closed
snake3ca opened this issue Apr 25, 2022 · 12 comments
Closed

Youtube plugin crashes on Ubuntu 22.04 #298

snake3ca opened this issue Apr 25, 2022 · 12 comments

Comments

@snake3ca
Copy link

snake3ca commented Apr 25, 2022

Context
Add-on Version: 6.8.18+matrix.1
Kodi Version: Kodi (19.4 (19.4.0) Git:19.4-Matrix). Platform: Linux 64-Bit
Kodi GUI Language: English
Operating System: Ubuntu 22.04, kernel: 5.15.0-27-generic
Operating System Language: English

Expected Behavior
Youtube videos play without crashing kodi.

Current Behavior
Playing a youtube video then exiting the youtube addon then playing another youtube video crashes kodi.

Steps to Reproduce
Play a youtube video, exit youtube addon, go back and try play another youtube video and it will crash kodi.

or

Goto youtube addon settings -> http server -> click on check my ip then once it shows the IP click check my ip again, kodi then crashes.

Other Info
Crashes with MPEG-Dash disable as well.

This shows up in dmesg after the crash

LanguageInvoker[944]: segfault at 8 ip 0000150c5df97aa0 sp 0000150c20bb9270 error 4 in libpython3.10.so.1.0[150c5deff000+2b5000

kodi_crashlog-20220425_090223.log

@pitsi
Copy link

pitsi commented May 5, 2022

I have the same issue in debian testing/unstable. Python is to blame for that. Most addons are developed on python 3.8, so issues on later versions of it are probable.
I had an addon that was constantly crashing when I was on 3.9, so I removed it. Today, that I am on 3.10, even twitch and youtube sometimes crash.

@cinnaboot
Copy link

Crashlog from plugin crashing kodi on Ubuntu 22.04
https://gist.github.com/cinnaboot/7549560ad9c6fc66abefa5f930211eec

Is there a way to get more useful python stack traces from kodi?

@dchristl
Copy link

dchristl commented Jul 1, 2022

I have the same problem with the latest Ubuntu LTS, except kodi doesn't crash. The first video starts without any issues, but on the 2nd one (no matter if in playlist or new one) Kodi's UI hangs indefinitely. No entry in log, just stuck. The only way out is to kill Kodi complete. If this is a problem with the new python version (currently 3.10.4), this will impact a lot of users when the 22.04.1 comes out in August. At this release the 20.04 LTS users will get this update nearly automatically.
Is there any way to support the fix of this bug. It seems there are some breaking changes in newer python versions or is this a bug in python? I'm not really a python developer, but I can help with testing or logs, if help is needed.

@crwolff
Copy link

crwolff commented Jul 2, 2022

I tested kodi on a freshly installed 22.04 VM with python 3.10.4, and I wasn't able to reproduce the failure. The only shortcut I took was copying my userdata folder from my HTPC so I didn't have to authenticate the plugin.

One thing to try is to activate the python faulthandler module and see if it gives any additional insights. (Note, I haven't tested this since it's working for me)

Modify addons/plugin.video.youtube/resources/lib/default.py to look like the following:

from youtube_plugin.kodion import runner
from youtube_plugin import youtube
import faulthandler

f = open('/tmp/kodi_dump.log', mode='w')
faulthandler.enable(f)
__provider__ = youtube.Provider()
runner.run(__provider__)

Update:
I can reproduce the crash by the following sequence:

  1. Install fresh Ubuntu-Mate 22.04 on Virtualbox (4 CPU, 4G RAM)
  2. Install Virtualbox guest additions
  3. Fully update
  4. Install Kodi from release PPA
  5. Install youtube plugin from XBMC repository (skip setup wizard, no API keys, no sign-in)
  6. Open youtube plugin
  7. Click 'Settings'
  8. Click 'Ok'

Kodi draws the main menu, freezes for ~60 seconds, then crashes with a segmentation fault. Faulthandler files are empty.

@dchristl
Copy link

dchristl commented Jul 4, 2022

Sometimes it works for me as well (~ 1 out of 5 times). I've attached a log with debugging enabled:
kodi.log

Workflow:

  • Fresh start of kodi, waiting for finished initialization.
  • Starting a random video
  • Stopping the video
  • Starting the video again
  • Kodi freezes (------ Window Init (DialogBusy.xml) ------ is always the last line)
  • No crash after 5 min
  • kill

I've enabled the faulthandler, but the file is empty.

@and3md
Copy link

and3md commented Sep 3, 2022

I noticed that when ssl verify is set to false everything works ok so it can be something with new openssl in last LTS (22.04).

In ~/.kodi/userdata/addon_data/plugin.video.youtube/settings.xml settings.xml change true to false in line:

<setting id="simple.requests.ssl.verify" default="true">false</setting>

This is not a good solution (potential security risk), but it can help plugin developers solve the problem if we determine where the problem is. So @dchristl Can you try this solution to confirm my assumption?

But remember no cert verification makes you vulnerable to man in the middle attack). I don't know how risky is using this hack but I found in youtube plugin sources code that turns off verification when you have old python installed.

    def verify_ssl(self):
        verify = self.get_bool(constants.setting.VERIFY_SSL, False)
        if sys.version_info <= (2, 7, 9):
            verify = False
        return verify

@tofurky
Copy link

tofurky commented Sep 4, 2022

for whatever reason, simple.requests.ssl.verify was set to false already on my install and i'm unfortunately still seeing crashes, especially after pressing OK after opening the settings (without changing anything) for the youtube addon:

[Sun Sep  4 16:25:41 2022] LanguageInvoker[1301]: segfault at 8 ip 00007f964e67caa0 sp 00007f95e6f34270 error 4 in libpython3.10.so.1.0[7f964e5e4000+2b5000]
[Sun Sep  4 16:25:41 2022] Code: ff 4d 89 e6 4d 89 e7 e9 e6 fe ff ff 66 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 f3 0f 1e fa 55 48 8b 4f f0 48 89 fd 48 8b 57 f8 <48> 8b 41 08 48 83 e2 fc 83 e0 03 48 89 0a 48 09 d0 48 89 41 08 48
[Sun Sep  4 16:25:41 2022] [drm] Got external EDID base block and 1 extension from "edid/nr818.bin" for connector "DP-5"
[Sun Sep  4 16:26:57 2022] LanguageInvoker[1392]: segfault at 8 ip 00007f004aadcaa0 sp 00007f0012b9a270 error 4 in libpython3.10.so.1.0[7f004aa44000+2b5000]
[Sun Sep  4 16:26:57 2022] Code: ff 4d 89 e6 4d 89 e7 e9 e6 fe ff ff 66 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 f3 0f 1e fa 55 48 8b 4f f0 48 89 fd 48 8b 57 f8 <48> 8b 41 08 48 83 e2 fc 83 e0 03 48 89 0a 48 09 d0 48 89 41 08 48
[Sun Sep  4 16:26:57 2022] [drm] Got external EDID base block and 1 extension from "edid/nr818.bin" for connector "DP-5"
[Sun Sep  4 16:27:27 2022] LanguageInvoker[1477]: segfault at 8 ip 00007efc08c01aa0 sp 00007efba0db0270 error 4 in libpython3.10.so.1.0[7efc08b69000+2b5000]
[Sun Sep  4 16:27:27 2022] Code: ff 4d 89 e6 4d 89 e7 e9 e6 fe ff ff 66 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 f3 0f 1e fa 55 48 8b 4f f0 48 89 fd 48 8b 57 f8 <48> 8b 41 08 48 83 e2 fc 83 e0 03 48 89 0a 48 09 d0 48 89 41 08 48
[Sun Sep  4 16:27:27 2022] [drm] Got external EDID base block and 1 extension from "edid/nr818.bin" for connector "DP-5"

setting it back to true didn't make a difference in brief testing.

maybe there are multiple issues affecting python 3.10?

ubuntu 22.04/x86_64 w/6:19.4+git20220330.0719-b738e65ae5-0~jammy and python 3.10.4-3ubuntu0.1

@dchristl
Copy link

dchristl commented Sep 5, 2022

I've done a little research and the problem is indeed python, like mentioned. Precisely it is the python invoker. The main bug is python/cpython#90228. There are several issues, caused by this in Kodi and other plugins (i.e. xbmc/xbmc#21243 or python/cpython#92036 . So, the current bug is not caused by the youtube-plugin. The python-bug seems to be fixed in main and the latest python 3.11 (some says it is also fixed in 3.10.5). The problem is that Kodi uses the default system python and this is not updateable in Ubuntu, because a lot of tools (like apt) depending on specific versions. So, there is no solution after all, but I've found a workaround for me avoiding the problem without breaking the system. This is based on installing latest python, patching Kodi to use this and use the newest python version only for Kodi and nothing else.

  1. Install patchelf and python 3.11 by using deadsnakes ppa
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.11-full libpython3.11 patchelf
  1. Patch kodi.bin to use the installed python version
sudo patchelf --replace-needed libpython3.10.so.1.0 libpython3.11.so.1.0 /usr/lib/x86_64-linux-gnu/kodi/kodi.bin
  1. Add the new and the old python to the alternatives
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2
  1. Change and test Kodi with the new version
    Your actual python-Version should be the system default version
python3 -V

outputs Python 3.10.4
Now you can change this to 3.11 by typing:

sudo update-alternatives --config python3

The output should be someting like this:

There are 2 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                 Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.10   2         auto mode
  1            /usr/bin/python3.10   2         manual mode
  2            /usr/bin/python3.11   1         manual mode

Press <enter> to keep the current choice[*], or type selection number:

Press 2 to change the system python to 3.11.

python3 -V

outputs now Python 3.11.0rc1

At this point you can start Kodi and all issues should be gone.

  1. Set python back to default and use this only for Kodi

At this point apt (and maybe some other Ubuntu tools) are broken, because they are depending on fixed python versions. So change back to default by:

sudo update-alternatives --config python3

and pressing 0

You can start kodi with a wrapper script or as oneliner by:

echo "2" | sudo update-alternatives --config python3; kodi; echo "0" | sudo update-alternatives --config python3

This sets python3.11 before starting Kodi and revert this change after closing it.

  1. Optional: Adding update-alternatives to sudoers to avoid password input

Before starting and after cosing Kodi you have to input your sudo password everytime to set the correct python. To avoid this add a line to sudoers by:

sudo visudo

Go to the end and add (Replace yourUsername with output of whoami!):
yourUsername ALL=(ALL) NOPASSWD: /usr/bin/update-alternatives --config python3

Now you can start and close Kodi without typing any password.

I use this workaround since almost a week and Kodi and the system are running without any problems. This works for me until Ubuntu's python-Version will be updated. The only drawbacks are:

  • It is possible that you have to repeat step 2 after any Kodi update
  • If the automatic system update (update-manager) is running when Kodi is also up, this results in an error.

@snake3ca
Copy link
Author

snake3ca commented Sep 7, 2022

Looks like this issue will be fixed in a future python3 update for ubuntu 22.04.

https://bugs.launchpad.net/ubuntu/+source/python3.10/+bug/1982108

@tofurky
Copy link

tofurky commented Sep 7, 2022

Looks like this issue will be fixed in a future python3 update for ubuntu 22.04.

https://bugs.launchpad.net/ubuntu/+source/python3.10/+bug/1982108

i enabled the proposed repos per https://wiki.ubuntu.com/Testing/EnableProposed and ran the following to update python3.10 before disabling the repo:

apt install python3.10

kodi is no longer crashing when saving youtube settings. thanks! it's too early to call it 100% fixed but it was consistently crashing upon saving settings before.

the actual package version is 3.10.6-1~22.04

@and3md
Copy link

and3md commented Sep 8, 2022

@dchristl @snake3ca @tofurky Thanks for your help, I've installed python test packages and I don't need to turn off SSL verification anymore, the kodi itself seems to be more stable too.

@snake3ca
Copy link
Author

Ubuntu has updated libpython3.10 to version 3.10.6 and the issue is now resolved. Closing issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants