Kodi Community Forum

Full Version: Deadlock in Krypton PVR during addon install/uninstall
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've been working on a custom PVR and have had a lot of trouble with installing/uninstalling the addon in Krypton (Windows and Windows Store). I wanted to let you know that I found the basic problem, maybe you guys can fix it before I have time to dig in deeper -- I wanted to let you know ASAP in case you can fix it and get it into the final Krypton release.

Note: still happens in Krypton RC3, but I have not tried the subsequent nightlies or a pull from the master branch.

> There appears to be a deadlock condition that occurs when the "Use Backend Channel Names" setting is enabled and you try to install or uninstall a PVR addon that supports channels. It will manifest as a UI lockup when you try to navigate after initiating the install/uninstall action in the Addon Manager; you will also never get the "Addon Installed" notification. My cursory examination showed that a number of threads (3, I believe it was) are waiting on the addon manager unique lock, and the offending one looks like where the PVR manager checks the "Use Backend Channel Names" setting and then checks if the PVR addon is disabled or not (->isDisabled() or something along those lines). I didn't dig in too deeply yet, but disabling the "Use Backend Channel Names" setting solves the problem; the PVR addon can be installed/uninstalled normally. No similar problems noted outside of install/uninstall, once the addon is installed you can enable "Use Backend Channel Names" and it loads just fine.

Anyway, I hope this helps point you in the right direction. I can spend some real time looking at it for you this weekend if nothing obvious jumps out or my description was inadequate.

Thanks!!
Thanks for reporting. I will look into it. It would be of help if you could post stack traces for the lookup scenario. Is the lockup 100% reproducible on your end?
(2017-01-20, 09:06)ksooo Wrote: [ -> ]Thanks for reporting. I will look into it. It would be of help if you could post stack traces for the lookup scenario. Is the lockup 100% reproducible on your end?

Yup, happens every time. I wasn't able to get the standard Kodi dump since I have to kill the process, but I saved off a Visual Studio minidump of the attached process (which is still 255MB!) and manually captured the stack traces for the 2 threads I believe are deadlocked. I can upload the minidump for you if it helps, just need to find a place to put it.

Hmmm.. new to these forums, don't see an upload link for the text files, forgive me for the mega-paste, but these are the threads I suspect are deadlocked:

THREAD 1

kodi.exe!PVR::CPVRClients::GetClient(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & strId, std:Confusedhared_ptr<ADDON::IAddon> & addon) Line 1180 + 0xf bytes

Code:
Not Flagged        7616    0    Worker Thread    thread_start<unsigned int (__stdcall*)(void *)>    RtlpWaitOnAddress    Idle
                             ntdll.dll!_NtWaitForAlertByThreadId@8()  + 0xc bytes    
                             ntdll.dll!@RtlpWaitOnAddressWithTimeout@16()  + 0x33 bytes    
                             ntdll.dll!RtlpWaitOnAddress()  + 0xa5 bytes    
                             ntdll.dll!RtlpWaitOnCriticalSection()  + 0xaa bytes    
                             ntdll.dll!RtlpEnterCriticalSectionContended()  + 0xd5 bytes    
                             ntdll.dll!_RtlEnterCriticalSection@4()  + 0x45 bytes    
                             kodi.exe!XbmcThreads::windows::RecursiveMutex::lock()  Line 54 + 0xc bytes    
                             kodi.exe!XbmcThreads::CountingLockable<XbmcThreads::windows::RecursiveMutex>::lock()  Line 60 + 0x16 bytes    
                             kodi.exe!XbmcThreads::UniqueLock<CCriticalSection>::UniqueLock<CCriticalSection>(CCriticalSection & lockable)  Line 127 + 0x19 bytes    
                             kodi.exe!CSingleLock::CSingleLock(const CCriticalSection & cs)  Line 39 + 0x1a bytes    
                             kodi.exe!PVR::CPVRClients::GetClient(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & strId, std::shared_ptr<ADDON::IAddon> & addon)  Line 1180 + 0xf bytes    
                             kodi.exe!PVR::CPVRClient::GetRunningInstance()  Line 126 + 0x5b bytes    
                             kodi.exe!ADDON::CAddonMgr::GetAddonsInternal(const ADDON::TYPE & type, std::vector<std::shared_ptr<ADDON::IAddon>,std::allocator<std::shared_ptr<ADDON::IAddon> > > & addons, bool enabledOnly)  Line 593 + 0x30 bytes    
                             kodi.exe!ADDON::CAddonMgr::GetAddons(std::vector<std::shared_ptr<ADDON::IAddon>,std::allocator<std::shared_ptr<ADDON::IAddon> > > & addons)  Line 474    
                             kodi.exe!ADDON::CAddonMgr::GetAvailableUpdates()  Line 456    
                             kodi.exe!ADDON::CAddonMgr::HasAvailableUpdates()  Line 468 + 0xc bytes    
                             kodi.exe!XFILE::RootDirectory(CFileItemList & items)  Line 442 + 0xc bytes    
                             kodi.exe!XFILE::CAddonsDirectory::GetDirectory(const CURL & url, CFileItemList & items)  Line 498 + 0x9 bytes    
                             kodi.exe!CGetDirectory::CGetJob::DoWork()  Line 68 + 0x3d bytes    
                             kodi.exe!CJobWorker::Process()  Line 69 + 0xf bytes    
                             kodi.exe!CThread::Action()  Line 221 + 0xf bytes    
                             kodi.exe!CThread::staticThread(void * data)  Line 134    
                             ucrtbased.dll!invoke_thread_procedure(unsigned int (void *)* const procedure, void * const context)  Line 92    
                             ucrtbased.dll!thread_start<unsigned int (__stdcall*)(void *)>(void * const parameter)  Line 115 + 0x10 bytes    
                             kernel32.dll!@BaseThreadInitThunk@12()  + 0x24 bytes    
                             ntdll.dll!__RtlUserThreadStart()  + 0x2f bytes    
                             ntdll.dll!__RtlUserThreadStart@8()  + 0x1b bytes

THREAD 2

kodi.exe!ADDON::CAddonMgr::IsAddonDisabled(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & ID) Line 812 + 0xf bytes

Code:
Not Flagged        5920    0    Worker Thread    thread_start<unsigned int (__stdcall*)(void *)>    RtlpWaitOnAddress    Below Normal
                             ntdll.dll!_NtWaitForAlertByThreadId@8()  + 0xc bytes    
                             ntdll.dll!@RtlpWaitOnAddressWithTimeout@16()  + 0x33 bytes    
                             ntdll.dll!RtlpWaitOnAddress()  + 0xa5 bytes    
                             ntdll.dll!RtlpWaitOnCriticalSection()  + 0xaa bytes    
                             ntdll.dll!RtlpEnterCriticalSectionContended()  + 0xd5 bytes    
                             ntdll.dll!_RtlEnterCriticalSection@4()  + 0x45 bytes    
                             kodi.exe!XbmcThreads::windows::RecursiveMutex::lock()  Line 54 + 0xc bytes    
                             kodi.exe!XbmcThreads::CountingLockable<XbmcThreads::windows::RecursiveMutex>::lock()  Line 60 + 0x16 bytes    
                             kodi.exe!XbmcThreads::UniqueLock<CCriticalSection>::UniqueLock<CCriticalSection>(CCriticalSection & lockable)  Line 127 + 0x19 bytes    
                             kodi.exe!CSingleLock::CSingleLock(CCriticalSection & cs)  Line 38 + 0x1a bytes    
                             kodi.exe!ADDON::CAddonMgr::IsAddonDisabled(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & ID)  Line 812 + 0xf bytes    
                             kodi.exe!PVR::CPVRClients::EnabledClientAmount()  Line 185 + 0x45 bytes    
                             kodi.exe!PVR::CPVRChannelGroup::Renumber()  Line 877 + 0x50 bytes    
                             kodi.exe!PVR::CPVRChannelGroups::SetSelectedGroup(std::shared_ptr<PVR::CPVRChannelGroup> group)  Line 486 + 0x1a bytes    
                             kodi.exe!PVR::CPVRChannelGroups::Load()  Line 322    
                             kodi.exe!PVR::CPVRChannelGroupsContainer::Load()  Line 71 + 0xb bytes    
                             kodi.exe!PVR::CPVRManager::Load(bool bShowProgress)  Line 661 + 0x15 bytes    
                             kodi.exe!PVR::CPVRManager::Process()  Line 550 + 0x29 bytes    
                             kodi.exe!CThread::Action()  Line 221 + 0xf bytes    
                             kodi.exe!CThread::staticThread(void * data)  Line 134    
                             ucrtbased.dll!invoke_thread_procedure(unsigned int (void *)* const procedure, void * const context)  Line 92    
                             ucrtbased.dll!thread_start<unsigned int (__stdcall*)(void *)>(void * const parameter)  Line 115 + 0x10 bytes    
                             kernel32.dll!@BaseThreadInitThunk@12()  + 0x24 bytes    
                             ntdll.dll!__RtlUserThreadStart()  + 0x2f bytes    
                             ntdll.dll!__RtlUserThreadStart@8()  + 0x1b bytes
All fine. Thanks for the stack traces. Good catch. This is clearly a deadlock between the two threads you sent the stacks for. No need for the minidump.

I will report back here if I have a fix.
The fix is pretty straight forward. I will post a link to a test build later tonight and would be glad if you could test the fix and report back.
@djp952: here we go. this is a link to a test build supposed to fix the deadlock: http://mirrors.kodi.tv/test-builds/win32...adlock.exe
Works perfectly! Thank you so much ksooo!

(Talk about a quick turnaround, too -- wow)

Big Grin
(2017-01-20, 23:40)djp952 Wrote: [ -> ]Works perfectly! Thank you so much ksooo!

(Talk about a quick turnaround, too -- wow)

Big Grin

You're welcome and please tell this the guys here and out there not getting tired to claim Team Kodi does not care for users/bugs/whatever ;-)
I was just starting to post a question about that. I have been trying to get wmc.pvr working and almost everytime I try to dis able it Kodi crashes.
(2017-01-23, 03:24)donbrew Wrote: [ -> ]I was just starting to post a question about that. I have been trying to get wmc.pvr working and almost everytime I try to dis able it Kodi crashes.


Which Kodi version?