TV Service taking long while to shutdown, delaying Windows shutdown/reboot

doskabouter

Community Plugin Dev
  • Premium Supporter
  • September 27, 2009
    2,952
    113
    Nuenen
    Country flag


    Isn't the solution in doing the stop actions in a separate thread?
    Because. as I see it (don't know if my assumptions are correct), when a preshutdown event is triggered, Service1.Onstop is executed, which calls _tvServiceThread.Abort() and _tvServiceThread.Join() which is just waiting until all is done.
    After that, the control is returned to whoever called the OnCustomCommand.

    As I understand from here (http://msdn.microsoft.com/en-us/magazine/cc164252.aspx#S2)
    The control handler, which handles the SERVICE_CONTROL_STOP, SERVICE_CONTROL_SHUTDOWN, and SERVICE_CONTROL_PRESHUTDOWN control codes, sets the service state to SERVICE_STOP_PENDING, creates a worker thread to do the work, and returns without further ado. The StopThread function can block as long as necessary and then set the service's state to SERVICE_STOPPED, informing the SCM, which can subsequently let the StartServiceCtrlDispatcher function return and terminate the process (provided it was the last service for shared process services). Just remember that if your service is in a pending state, it needs to regularly update the service's state with an incrementing checkpoint value to assure the SCM that it is not hanging.
    this is a better way

    Edit: sorry to mess around in archived discussions, but here's where the link in the jira call pointed to :)
     

    michael_t

    Portal Pro
    November 30, 2008
    1,258
    113
    Isn't the solution in doing the stop actions in a separate thread?
    Because. as I see it (don't know if my assumptions are correct), when a preshutdown event is triggered, Service1.Onstop is executed, which calls _tvServiceThread.Abort() and _tvServiceThread.Join() which is just waiting until all is done.
    After that, the control is returned to whoever called the OnCustomCommand.

    As I understand from here (http://msdn.microsoft.com/en-us/magazine/cc164252.aspx#S2)
    The control handler, which handles the SERVICE_CONTROL_STOP, SERVICE_CONTROL_SHUTDOWN, and SERVICE_CONTROL_PRESHUTDOWN control codes, sets the service state to SERVICE_STOP_PENDING, creates a worker thread to do the work, and returns without further ado. The StopThread function can block as long as necessary and then set the service's state to SERVICE_STOPPED, informing the SCM, which can subsequently let the StartServiceCtrlDispatcher function return and terminate the process (provided it was the last service for shared process services). Just remember that if your service is in a pending state, it needs to regularly update the service's state with an incrementing checkpoint value to assure the SCM that it is not hanging.
    this is a better way

    Edit: sorry to mess around in archived discussions, but here's where the link in the jira call pointed to :)
    The things are not so easy with managed code (.NET). I found no explicit way to set the service state to SERVICE_STOPPED, which is necessary to inform the SCM about a successful stop of the service. Usually this state is set after a successful return from the OnStop event handler. But the OnStop event is not triggered when you activate the pre-shutdown event. So the TV Controller is stopped prior to the other services by the pre-shutdown event handler which eliminates dependency errors (MySQL). But without setting the SERVICE_STOPPED state the SCM runs into a timeout (usually 10 sec - some reported longer...).
    So the trick is that the OnStop event has to be raised by the SCM though the pre-shutdown event is enabled. This is done by the patch I found in an internet blog and provided for MP. It triggers the SCM OnStop event out of the preshutdown event handler. Thus (I assume) the SERVICE_STOPPED state is entered implicitely after the OnStop handler returns (like if the pre-shutdown event were not activated).

    Michael
     

    catavolt

    Design Group Manager
  • Team MediaPortal
  • Administrator
  • August 13, 2007
    12,345
    113
    Lanzarote
    Country flag
    Hi Michael, tested the above TVService.exe and it works fine.
    Shutdown time with original TVService.exe: 32 secs.
    Shutdown time with new TVService.exe: 13 secs.
    This is a significant improvement ;)
    THX (y)
     

    badboyxx

    Portal Pro
    June 15, 2012
    684
    28
    Country flag

    skorz

    MP Donator
  • Premium Supporter
  • December 19, 2011
    242
    28
    Deutschland
    As i understand it the right way, this fix will solve problems where the tv service needs too long to shutdown? i have every time the pc goes to sleep the error message that the tv service cant shutdown completely after a preshutdown event...

    as i have 1.7 pre, is this fix included?
     

    lukeinv

    Portal Member
    January 22, 2010
    11
    1
    Maybe we can post binarys based on MP 1.6.0 for this issue?
    @Sebastiii are you able to do this? :)
    I just committed a new branch based on MP 1.6 from my local git repository for this (MP1-3172_TVService_ignores_shutdown_(reopened)) and created a new review for it (MP1CR-244). The binary for testing is attached.

    Michael

    Hi Michael, the new TV service is working fine except loading plugins:
    [2014-03-23 01:29:53,539] [Log ] [TVService] [INFO ] - TV Service: Load plugins
    [2014-03-23 01:29:53,539] [Log ] [TVService] [INFO ] - PluginManager: TvEngine.ComSkipLauncher is incompatible with the current tvserver version and won't be loaded!
    [2014-03-23 01:29:53,555] [Log ] [TVService] [INFO ] - PluginManager: TvEngine.ConflictsManager is incompatible with the current tvserver version and won't be loaded!
    [2014-03-23 01:29:53,555] [Log ] [TVService] [INFO ] - PluginManager: Loaded MPExtended PowerScheduler plugin version:0.5.4 author:MPExtended Developers
    [2014-03-23 01:29:53,570] [Log ] [TVService] [INFO ] - PluginManager: TvEngine.PowerScheduler.PowerSchedulerPlugin is incompatible with the current tvserver version and won't be loaded!
    [2014-03-23 01:29:53,570] [Log ] [TVService] [INFO ] - PluginManager: TvEngine.ServerBlaster is incompatible with the current tvserver version and won't be loaded!
    [2014-03-23 01:29:53,570] [Log ] [TVService] [INFO ] - PluginManager: TvEngine.TvMovie is incompatible with the current tvserver version and won't be loaded!
    [2014-03-23 01:29:53,586] [Log ] [TVService] [INFO ] - PluginManager: TvEngine.WebEPGImport is incompatible with the current tvserver version and won't be loaded!
    [2014-03-23 01:29:53,586] [Log ] [TVService] [INFO ] - PluginManager: TvEngine.XmlTvImporter is incompatible with the current tvserver version and won't be loaded!
    (I'm only using bold ones)

    and I'm wondering is it possible to fix it
    Thanks
     

    lukeinv

    Portal Member
    January 22, 2010
    11
    1
    Hi Michael,
    I have currently installed MP 1.7 PreRelease installed (tv service version - 1.6.100.0) and shut down takes long time
    Combination of MP 1.7 PreRelease + tv service 1.6.0.0 performs much quicker shutdown but it is incompatible with few plugins
    Is there newer version of tv service than 1.6.100.0 one?

    Thanks
     
    Top Bottom