SSDPServerController.OnExpirationTimerElapsed: Cannot acquire synchronization lock. Maybe a deadlock (3 Viewers)

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,578
    8,226
    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
    66
    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,578
    8,226
    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,578
    8,226
    Home Country
    New Zealand New Zealand

    pnyberg

    Portal Pro
    August 21, 2006
    405
    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

    Does anyone else have problem with long (several hours) pauses of TV broadcasts? If I pause and forget, I can still resume TV the next day, but if I try to change channel or stop, MP freezes. Only way to fix is to restart both MP and TV Service. Sometimes I need to restart PC It seems that TVServer cannot proprtly handle large...
    Does anyone else have problem with long (several hours) pauses of TV broadcasts? If I pause and forget, I can still resume TV the...
    Does anyone else have problem with long (several hours) pauses of TV broadcasts? If I pause and forget, I can still resume TV the...
    Replies
    0
    Views
    395
    When I tested MP 2.5 some months ago using TVE3.5, I found that "scan for channels" failed to find any channels when I selected a DVB-T2 tuner (a TBS 6284) :(, but succeeded when I used a DVB-T tuner (a Pinnacle 2000i) :). Obviously the Pinnacle found only those channels broadcast in DVB-T MUXes (in the UK we have both DVB-T MUXes and...
    When I tested MP 2.5 some months ago using TVE3.5, I found that "scan for channels" failed to find any channels when I selected a...
    Hi all Running 1.7.1.0 TV Server as part of a full upgrade to MP2 2.5 setup After some problems with retuning (solved -...
    Replies
    3
    Views
    739
    Concerning the HDHomerun Expand. This has 4 tuners, and is DVB-C It has, of course, latest software from Silicondust already installed, version name 20230713. BDA compatibility mode is set to MediaPortal. Advanced --- BDA driver set to InjectCVCT plus automatically select from tuners recommended.
    Concerning the HDHomerun Expand. This has 4 tuners, and is DVB-C It has, of course, latest software from Silicondust already...
    I have set up MP1 .34 on Win 11 Pro. I have a HDHomerun Expand DVB-C tuner, which I have used for about 10 years. Until about 2021...
    Replies
    13
    Views
    1K
    Just those I attached. I messed about with task priorities MP/TV-Server/SQL-Server and the issue changed to the skin.. I would do something, but it would be 10's of seconds before the action happened. Doing an Alt-Tab would flush the actions. Too weird lol!! So, with some flak from the family, I had to give in. I just did a...
    Just those I attached. I messed about with task priorities MP/TV-Server/SQL-Server and the issue changed to the skin.. I would do...
    So, this one has me quite stumped. Have tried ) and a few things - driver updates, kicking the box, threatening it with a static...
    Replies
    8
    Views
    826
    MP1 MP2 MP2 - V2.5 Media Source DE
    @Brownard, just a stupid question. Yes it works now by manually entering the path. However when i try to edit the settings (like because i want to disable the share watch) I can select my Media Source, however i seems to only briefly been shown and the goes back to the list. So i cannot actually edit it. Can et bee due to the "long"...
    @Brownard, just a stupid question. Yes it works now by manually entering the path. However when i try to edit the settings (like...
    I had to replace my NAS and after reinstalling a new one i thought. Lets modify the Media Source. - However that did not work "if"...
    Replies
    25
    Views
    3K
    Top Bottom