PowerScheduler synchronization/concurrency bug (1 Viewer)

seco

Retired Team Member
  • Premium Supporter
  • August 7, 2007
    1,575
    1,239
    Home Country
    Finland Finland
    There's seems to be some kind of synchronization problem in TV-Server PowerScheduler when entering to standby.

    NullReferenceException can be found from error.log which is caused by _powerManager.AllowStandby() call in PowerScheduler.cs get_DisAllowShutdown() method.

    I did testing with SVN 19574 compiled as debug build, tv.log has couple of debug log lines added by me and error.log tells the line number where exception occurs.

    The main problem is that Stop() method is called for PowerScheduler plugin just before entering standby, which sets _powerManager to null, but after that (almost at the same time) DisAllowShutdown() method gets called anyway (call is caused by another thread) and error occurs.

    Already discussed about the problem @ IRC with Bavarian. I don't know how someone else than me could reproduce this, for me it happens every time when entering to standby (and because of that, automatic wake up doesn't work if there are scheduled recordings or EPG grab, because final wake up time doesn't get calculated & set correctly).

    (Original thread was: https://forum.team-mediaportal.com/...ake-up-grap-epg-record-scheduled-shows-41999/ , it can be ignored)

    TV-Server Version: 1.0 RC1 SVN 19574
    MediaPortal Version: 1.0 RC1 SVN 19574
    MediaPortal Skin: BlueTwo Wide
    Windows Version: Windows XP SP3
    CPU Type: Intel E8200 2.66GHz
    HDD: Seagate IV 40GB
    Memory: Corsair 2GB 800MHz
    Motherboard: Asus P5E-VM HDMI
    Video Card: Intel X3500 IGP HDMI
    Video Card Driver:
    Sound Card: Realtek HD Integrated
    Sound Card AC3: AC3Filter
    Sound Card Driver:
    1. TV Card: FireDTV DVB-C
    1. TV Card Type:
    1. TV Card Driver:
    2. TV Card:
    2. TV Card Type:
    2. TV Card Driver:
    3. TV Card:
    3. TV Card Type:
    3. TV Card Driver:
    4. TV Card:
    4. TV Card Type:
    4. TV Card Driver:
    MPEG2 Video Codec: nVidia Purevideo
    MPEG2 Audio Codec: AC3Filter
    h.264 Video Codec: CoreAVC 1.7
    Satelite/CableTV Provider:
    HTPC Case: Antec Fusion 2
    Cooling: Stock
    Power Supply: Antec 430W
    Remote: Logitech diNovo Mini / FireDTV Remote
    TV: Toshiba 46ZF355
    TV - HTPC Connection: HDMI
     

    tourettes

    Retired Team Member
  • Premium Supporter
  • January 7, 2005
    17,301
    4,800
    I have seen that same error in logs from time to time, but I newer have seen any issues that are caused by it.
     

    seco

    Retired Team Member
  • Premium Supporter
  • August 7, 2007
    1,575
    1,239
    Home Country
    Finland Finland
    • Thread starter
    • Moderator
    • #3
    For me the issue is that (scheduled) wake up doesn't work anymore, it worked fine in 0.2.3.0.

    I don't fully understand how this should work.

    There is a line
    2008-07-08 18:15:35.703125 [Powerscheduler Suspender]: PowerScheduler: Set wakeup timer to wakeup system in 1424,15494791667 minutes

    in the tv.log which seems to be correct.

    But when PowerEventThread is running the same code and the error occurs, execution never reaches that point because of the NPR.

    So what happens to wakeup timer then? If it's not calculated & set correctly because of the NPR, the wake up doesn't work? In any case, I'd consider this as a bug.
     

    seco

    Retired Team Member
  • Premium Supporter
  • August 7, 2007
    1,575
    1,239
    Home Country
    Finland Finland
    • Thread starter
    • Moderator
    • #4
    Powerscheduler.cs OnPowerEvent():

    case PowerEventType.StandBy:
    _denySuspendQuery = true; // reset the flag

    Log.Debug("PowerScheduler: System is going to standby");
    _standby = true;
    _timer.Enabled = false;
    _controller.EpgGrabberEnabled = false;
    FreeTVCards();
    SendPowerSchedulerEvent(PowerSchedulerEventType.EnteringStandby, false);
    SetWakeupTimer();
    return true;

    Is the call order causing the problem?

    FreeTVCards(); ---> DeInits controller which stops the plugin -> _powerManager is set to null
    SendPowerSchedulerEvent(PowerSchedulerEventType.EnteringStandby, false); ---> Dunno what effects this has :)
    SetWakeupTimer(); ---> _powerManager is used here --> NullReferenceException


    EDIT:

    In my opinion SetWakeupTimer(); call should not be in OnPowerEvent() method because it is already called before by PowerScheduler Suspender thread.
     

    seco

    Retired Team Member
  • Premium Supporter
  • August 7, 2007
    1,575
    1,239
    Home Country
    Finland Finland
    • Thread starter
    • Moderator
    • #6
    Wake up is working for me now but I don't know why. I don't use any modified Powerscheduler.dll at the moment so I still get the NullReferenceException to error.log every time when entering to standby but the wake up seems to be fine at least with scheduled recordings.

    Only thing I did was that I turned Intel EIST and C1E modes on in BIOS.

    Anyway, NPR is still a bug that should be fixed. I don't know does it effect the wake up timer somehow.

    I'll do more testing with EIST & C1E settings when I come back from Miami next week. I also have a new problem now when wake up is working. I use "Restart Mediaportal when resuming from standby" option and because of that I get Windows error message saying something that "Invalid window handle" when resuming from standby. When I close the error dialog, MP restarts up fine.
     

    Bavarian

    Retired Team Member
  • Premium Supporter
  • April 4, 2005
    698
    167
    Germany, Bayern
    Home Country
    Germany Germany
    Hi seco,

    I have fixed the problem. Please give attached PowerScheduler.dll a try. With this dll the problem should be gone.


    Bavarian
     

    seco

    Retired Team Member
  • Premium Supporter
  • August 7, 2007
    1,575
    1,239
    Home Country
    Finland Finland
    • Thread starter
    • Moderator
    • #8
    Hi seco,

    I have fixed the problem. Please give attached PowerScheduler.dll a try. With this dll the problem should be gone.


    Bavarian

    Hi Bavarian!

    I tried the attached PowerScheduler.dll but the error remains.

    1. Going to sleep and wake up was fine, so both of those are working.

    2. BUT, For some reason, the scheduled recording didn't start at all!

    3. NPR error is still in the error.log

    I really wonder why the recording didn't start and was it caused by the modifications that you made, sounds very unlikely. I can see the recording in the "Scheduled" listing but it's not recording. I tried to record "Tulosruutu" at 22.20

    Logs attached.
     

    seco

    Retired Team Member
  • Premium Supporter
  • August 7, 2007
    1,575
    1,239
    Home Country
    Finland Finland
    • Thread starter
    • Moderator
    • #9
    Final test run,

    Settings:

    1. TV-Server reinitialize after wake up OFF

    2. Mediaportal restart after wake up ON

    Steps:

    1. Computer starts up, MP starts up automatically

    2. I go to MyTV and schedule a recording through EPG

    3. I return to Home screen and wait 5 minutes for shutdown

    4. Shutdown occurs

    5. Wake up occurs, recording is started automatically

    6. I tune to few channels

    7. I stop TV, delete recording that is going on, recording is stopped

    Results:

    1. Everything is working GREAT! :D No NRE in error.log anymore.
     

    seco

    Retired Team Member
  • Premium Supporter
  • August 7, 2007
    1,575
    1,239
    Home Country
    Finland Finland
    • Thread starter
    • Moderator
    • #10
    Bavarian,

    I'm curious what changes did you make? Will those be in SVN at some point?

    Also do you yet know what is causing the TVServer re-initializing fail if it has been turned ON in configuration?
     

    Users who are viewing this thread

    Top Bottom