Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Sporadic crash when during on my TV/Receiver due to double close() on the same fd in ActiveAE #16258
Describe the bug
Here is a clear and concise description of what the problem is:
Kodi crashes sporadically when I turn on my TV and receiver since I upgraded to Ubuntu 19.04. There is a double close somewhere on the ActiveAE thread which is racing against the PeripBusUSBUdev. libudev has an assert when close returns EBADF. When I turn the TV on, it triggers udev_enumerate_scan_devices. This has been difficult to debug due to the sporadic nature of the race condition. I've straced kodi-x11 with close() calls, but if I add openat to the list, it disturbs the timing enough that I haven't been able to reproduce with that strace attached. It happens at least 50% of the time turning my TV on with no strace attached.
Here is a clear and concise description of what was expected to happen:
Kodi should not crash sporadically when turning on my TV.
Kodi crashes sporadically when turning on my TV.
Steps to reproduce the behavior:
The debuglog can be found here:
Stack strace from the core dump, it asserts inside libudev due to the double close on the other thread:
Here are some links or screenshots to help explain the problem:
Additional context or screenshots (if appropriate)
Here is some additional context or explanation that might help:
Used Operating system:
note: Once the issue is made we require you to update it with new information or Kodi versions should that be required.
I did an strace with open, openat, close, creat and ioctl to try to better see what's going on. For the ActiveAE thread: The openat is on /dev/snd/controlC0. There is a double close of that file descriptor later on the thread. There must be a bad call to snd_ctl_close somewhere. I'll try to get a debug build of Kodi to trace those calls.
I finally had time to debug this more. It's a bug in jack2. I'm not even using jack on my system. However, with alsa-plugins >= 1.1.7, the ALSA to JACK plugin layer is enabled by default. Ubuntu 19.04 ships with alsa-plugins 1.1.8. Ubuntu 18.10 had alsa-plugins 1.1.6 which explains the behavior change. I'll send a patch to jack2.
Fix merged in jack: jackaudio/jack2@dad4b57
Kodi is calling EnumerateDevice over the list of ALSA sinks, and then TryDevice is opening each of them. For the jack plugin that Ubuntu 19.04 enables by default, that tries to open jack. However, libjack has a double close when it fails to connect to jackd because it closes the socket on error, and then closes it again in the cleanup code. I'm not running jackd. I don't even have it installed. That 2nd close races against the udev enumerator in kodi to cause the sporadic crash.
I think the only real workaround from the kodi side would be to ignore the ALSA jack plugin unless a user explicitly wants it.