SSDPServerController.OnExpirationTimerElapsed: Cannot acquire synchronization lock. Maybe a deadlock (1 Viewer)

MrTechno

Retired Team Member
  • Premium Supporter
  • February 27, 2011
    1,256
    511
    London
    Home Country
    United Kingdom United Kingdom
    Adding IP filtering to MP2 server reduced the lock ups but they still happened on my machine. I haven't found the root cause, I just disabled VPN.
     

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,544
    8,236
    Home Country
    New Zealand New Zealand
    Well hmmm...

    The logs in the other thread seem to only show the message after TVE attempts to call SSDPClientController.Close(), whereas the logs in this thread seem to show the message while MP2 Server should be running and the SSDP controller still active. In short: I suspect the existence of two distinct causes or scenarios. TVE's Close() issue is probably much easier to resolve.

    Looking at the Close() function:
    https://github.com/MediaPortal/Medi...tructure/CP/SSDP/SSDPClientController.cs#L350

    ...it seems odd to me is that _isActive = false and the socket = null loop aren't all within the same lock. Surely an atomic/locked shutdown would be cleaner/better? The assumption seems to be that if Close() acquires the lock and is able to set _isActive false then the Receive() handling will "die" without any major problem and we should be okay to close the sockets... but I'm not so sure about that assumption.

    Looking at the Receive() functions:
    https://github.com/MediaPortal/Medi...tructure/CP/SSDP/SSDPClientController.cs#L111
    https://github.com/MediaPortal/Medi...tructure/CP/SSDP/SSDPClientController.cs#L149

    Obviously they only acquire the lock for checking _isActive and then release it immediately. Crucially: there is no locking around the socket access that happens later (eg. socket.EndReceiveFrom()).

    Consider the following sequence with two threads.
    1. Thread A: Receive() invoked, lock acquired, _isActive is true so processing will continue. Lock released.
    2. Thread B: Close() invoked, lock acquired, _isActive is set false. Lock released.
    3. Thread A: The if (socket == null) check is passed before Thread B sets the shared socket reference to null. Local socket reference acquired (so Thread B setting socket to null will not have immediate effect).
    4. Thread B: Lock acquired, local socket reference acquired, shared socket reference set null. Lock released.
    5. Thread A: EndReceiveFrom() invoked on local socket reference.
    6. Thread B: Close() invoked on local socket reference either directly or within NetworkHelper.DisposeSSDPMulticastSocket().

    What happens?
    I don't know for sure, but it might not be good.
    If EndReceiveFrom() unblocks on Close() and an exception is thrown in Thread A everything would be fine I think (the exception would be caught and Receive() would return).
    However, if Close() waits for EndReceiveFrom() to receive and return but EndReceiveFrom() never does actually receive or time out... that could be our lovely deadlock. Close() blocks TVE forever.

    It interests me to see that there is an optional timeout parameter on socket.Close() which we currently do not use. ;)

    I suspect there could potentially be other issues lurking in the Receive() processing too, simply due to the fact that _isActive is only checked at the start of Receive() and not anywhere within the processing (and Close() does not close atomically within the lock).

    Plausible?
    Garbage?
    :)
     

    breese

    Retired Team Member
  • Premium Supporter
  • July 11, 2011
    3,902
    770
    67
    Arlington Heights, Illinois
    Home Country
    United States of America United States of America
    I have too as seeing one thread is MP1 and another thread is MP2, is there common code (outside of TVE) that might produce this issue?
     

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,544
    8,236
    Home Country
    New Zealand New Zealand
    is there common code (outside of TVE) that might produce this issue?
    Not if you exclude TVE. The issue is in MP2's UPnP library (which is used for TVE CableCARD tuner support) - that much is very clear. With TVE, even if you don't have a CableCARD tuner, the SSDP/UPnP detector is always used so there is always the potential for problems.
     

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,544
    8,236
    Home Country
    New Zealand New Zealand

    pnyberg

    Portal Pro
    August 21, 2006
    404
    36
    Stockholm
    Home Country
    Sweden Sweden
    Hello,

    I have this with the latest MP2 Summer 2015 release of MP2 server as well. But only when closing/stopping the server.
    Everything works okay until, stopping the server, eventually it will stop - but is this known error?

    Attaching log.
     

    Users who are viewing this thread

    Similar threads

    I made some updates to the Wiki page describing the <import> and <include> tags, including adding a couple of new xml examples. For the first example, I highlighted the example text and eventually found the location in the menus where I could select the CODE macro to have the example text formatted as a code example. So far, so good...
    I made some updates to the Wiki page describing the <import> and <include> tags, including adding a couple of new xml examples. For...
    I made some updates to the Wiki page describing the <import> and <include> tags, including adding a couple of new xml examples. For...
    Replies
    0
    Views
    516
    maybe setting loglevel to debug might pinpoint the difference between normal and stuck? Preferable with as much disabled as possible also try to see if anything is happening during stuck for the mediaportal process(resource monitor, disk activity, cpu usage, anything) maybe other programs competing for resouces?
    maybe setting loglevel to debug might pinpoint the difference between normal and stuck? Preferable with as much disabled as...
    Since over a year my MP sometimes stucks while showing the welcome screen. It started once a week now it happens every second time...
    Replies
    4
    Views
    1K
    Your timing is great.....I just got home myself!! :) A little confusion for me here! There are 2 x files in the folder......one is x86, and other is x64 Wondering if I should be selecting the x64.....since I'm installing the 64bit version? UPDATE Transferred both files to the destination folder, and labelled appropriately. This way...
    Your timing is great.....I just got home myself!! :) A little confusion for me here! There are 2 x files in the folder......one is...
    Am a long time MP1 user, and have successfully been running the x64 version since it first appeared. Recently, problem of black...
    Replies
    10
    Views
    2K
    If you’re planning to submit a pull request, let’s go through the list of issues and their solutions. I or someone from the team will create a Jira ticket, and for each ticket, you’ll make the changes and submit a pull request. This will be transparent and straightforward.
    If you’re planning to submit a pull request, let’s go through the list of issues and their solutions. I or someone from the team...
    I'm very glad to see that mediaportal 1 is on github, where ordinary devs with github accounts can make contributions. Please can...
    Replies
    7
    Views
    1K
    After many hours of troubleshooting I've given up and accepted that it's just "one of these things" when using madVR for watching live TV. I've now ticked the box to "Use EVR for LiveTV", with a default display refresh rate of 50Hz. In combination with tweaking some of the Nvidia 3D settings for the MP executable only, I now have a...
    After many hours of troubleshooting I've given up and accepted that it's just "one of these things" when using madVR for watching...
    Every so often, when I switch to a TV channel, my MP client stops accepting user inputs, either from the remote or keyboard/mouse...
    Replies
    30
    Views
    8K
    Top Bottom