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,577
    8,224
    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
    65
    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,577
    8,224
    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,577
    8,224
    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

    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
    2K
    Hi, you can try the new installer from this post if you like.
    Hi, you can try the new installer from this post if you like.
    Hello, I came from MediaPortal 1.30 and wanted to Update on 1.32 x64 Edition. I cleanly uninstalled 1.30 first and then installed...
    Replies
    7
    Views
    829
    I can confirm that. After reinstalling MP1.31(x86) I mistakenly installed the x64 version MpUrlSourcesplitter. Then I got the error. After uninstalling MpUrlSourcesplitter(x64) I installed the MpUrlSourcesplitter(x86). But the error message still comes.
    I can confirm that. After reinstalling MP1.31(x86) I mistakenly installed the x64 version MpUrlSourcesplitter. Then I got the...
    Just completed a clean install of Win 10 followed by MP 1.31. During install the installer hung up because I didn't have .net 3.5...
    Replies
    3
    Views
    533
    @doskabouter That fixed it, thanks!
    @doskabouter That fixed it, thanks!
    I just upgraded to 1.32 and now, when I start TV-Service Config, I get this error: [2024-01-31 09:33:13,138] [Log ] [SetupTv...
    Replies
    2
    Views
    553
    Nice you could resolve the issue!
    Nice you could resolve the issue!
    I have MediaPortal 2.5 Server installed on one computer and Mediaportal 2.5 client on another. The client is connected to the...
    Replies
    6
    Views
    570
    Top Bottom