ClosingForInstall is true after updating a window service

Hi,

I have a problem with wyUpdate updating a window service. I use this link to do the update: http://wyday.com/wybuild/help/silent-update-windows-service.phpAnd also this : http://wyday.com/wybuild/help/services.php

But it doesnt work properly. The service is updated, but in the OnStart event the auBackend.CloseForInstall is still true, so my code to open my service host is not executed.

And more to that, when I check in the event viewer I dont see any stop event, only a start event. So I wonder if my update action is working properly.

Heres a sample of my code:

/// <summary>/// Initializes the automatic updater./// </summary>private void InitializeAutomaticUpdater(){_automaticUpdaterBackend = new AutomaticUpdaterBackend();_automaticUpdaterBackend.GUID = "some guid";// With UpdateType set to Automatic, you're still in// charge of checking for updates, but the// AutomaticUpdaterBackend continues with the// downloading and extracting automatically._automaticUpdaterBackend.UpdateType = UpdateType.Automatic;// We set the service name that will be used by wyUpdate// to restart this service on update success or failure._automaticUpdaterBackend.ServiceName = ServiceName;

_automaticUpdaterBackend.wyUpdateCommandline = "/fromservice -server=\"" + UpdatePath + "/wyserver.wys\" -updatepath=\"" + UpdatePath + "\"";

_automaticUpdaterBackend.UpdateFailed += AutomaticUpdaterUpdateFailed;_automaticUpdaterBackend.CheckingFailed += AutomaticUpdaterCheckingFailed;_automaticUpdaterBackend.ReadyToBeInstalled += AutomaticUpdaterReadyToBeInstalled;_automaticUpdaterBackend.DownloadingFailed += AutomaticUpdaterDownloadingFailed;_automaticUpdaterBackend.ExtractingFailed += AutomaticUpdaterExtractingFailed;

// Initialize() and AppLoaded() must be called after events have been set.// Note: If there's a pending update to be installed, wyUpdate will be// started, then it will talk back and say "ready to install,// you can close now" at which point your app will be closed._automaticUpdaterBackend.Initialize();_automaticUpdaterBackend.AppLoaded();}

/// <summary>/// Starts the host./// </summary>/// <param name="args"></param>protected override void OnStart(string[] args){InitializeAutomaticUpdater();

if (!_automaticUpdaterBackend.ClosingForInstall){CheckForUpdate();OpenHost();}}

/// <summary>/// Stops the host./// </summary>protected override void OnStop(){CloseHost();}

/// <summary>/// Performs the wyBuild update./// </summary>/// <param name="sender">Sender</param>/// <param name="args">Event arguments</param>private static void AutomaticUpdaterReadyToBeInstalled(object sender, EventArgs args){if (_automaticUpdaterBackend.UpdateStepOn == UpdateStepOn.UpdateReadyToInstall){CloseHost();_automaticUpdaterBackend.InstallNow();}}

/// <summary>/// Checks for update./// </summary>private static void CheckForUpdate(){if (_automaticUpdaterBackend != null && _automaticUpdaterBackend.UpdateStepOn != UpdateStepOn.DownloadingUpdate&& _automaticUpdaterBackend.UpdateStepOn != UpdateStepOn.Checking){_automaticUpdaterBackend.ForceCheckForUpdate();}}

Because of this, when my service is updated, when I call it from my application I get an endpoint error.

wyUpdate version : 2.6.14

Because of this, when my service is updated, when I call it from my application I get an endpoint error.

I'm going to need more information on the error you're actually getting. Copy and paste the full error message.

Also, does your service actually close on "_automaticUpdaterBackend.InstallNow()"?

Wyatt wrote:> Also, does your service actually close on "_automaticUpdaterBackend.InstallNow()"?

As I said, I don't see anything in the event viewer related to a stop service, even if I log my own information on OnStop() event. But the exe running the service gets updated, so I think my service is stopped. Is there any other way to confirm this?

Wyatt wrote:> I'm going to need more information on the error you're actually getting. Copy and> paste the full error message.

The error here is irrelevent, because it's a message related to the missing endpoint which is the part (call to OpenHost()) that is not executed in the !ClosingForInstall condition which initialize my endpoint, but still here it is :

"There was no endpoint listening at net.pipe://localhost/Test that could accept the message. This is often caused by an incorrect address or SOAP action.

Server stack trace:at System.ServiceModel.Channels.PipeConnectionlnitiator.GetPipeName(Uri un)at address, Un via)at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)at System.ServiceModel.Channels.ClientFramingDuple.xSessionChannel.OnOpen(TimeSpan timeout)at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)at channel, TimeSpan timeout)at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout CallOnceManager cascade)at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[J ins, Object[] outs, TimeSpan timeout)at System.ServiceModel.Channels.ServiceChannel.CaIl(String action, Boolean oneway, ProxyOperationRuntime operation, Object[J ins, Object[] outs)at System.ServiceModel.Channels.ServiceChannelProxyJnvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)at System.ServiceModel.Channels.ServiceChannelProxyJnvoke(JMessage message)

Exception rethrown at [O]:at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessageQMessage reqMsg, IMessage retMsg)at System.Runtime Rem oting.Proxies. RealProxy.Privatelnvoke(MessageData& msgData, 1nt32 type)at Interface.LaunchCommandProcess(String fileName, String arguments)at Library.ProcessUtils.LaunchServiceProcess(String fileName, String parameters)at Client.Program.ExecuteCommandWithService()"

It almost sounds like you're getting the exception the first time your app tries to update. So your service crashes closed, wyUpdate quickly installs your updated files, then your service is restarted by Windows. This can cause a race condition for a file wyUpdate needs to update (to tell your app that it has already been updated).

Replace your current OnStop() function with this:

/// <summary>/// Stops the host./// </summary>protected override void OnStop(){	if (!_automaticUpdaterBackend.ClosingForInstall)		CloseHost();}

Tell me if this works.

Still same issue, there's no stop service in event viewer, I think OnStop() doesn't get called at all when InstallNow() is called. 🤔

This is the definition of my service in wix :

<ServiceInstall Id="$(var.Service.TargetFileName)" Name="Test" Description="Test Service" DisplayName="Test Service" Type="ownProcess" Start="auto" Account="LocalSystem" ErrorControl="normal" />

Is there something missing?

Also what are the correct step that I should see if Iog OnStart, OnStop event when the service is updated?

OnStart();CheckForUpdate();InstallNow();OnStop();OnStart();CheckForUpdate();OpenHost();

thanks for your help

Email me at wyatt@wyday.com. I think I might have found the cause of the problem. We're using Environment.Exit() to stop the service and this may be causing problems with your current ErrorControl setting for the service.

I want you to try a test version of the AutomaticUpdater to see if I'm right.

Just wondering why do we have the if (!auBackend.ClosingForInstall) in the OnStart service? Is there any chance that the service would be restarted before the update is completed?

Just wondering why do we have the if (!auBackend.ClosingForInstall) in the OnStart service?

So you don't start threads and process and other time consuming operations when you'll have to stop them all when the ReadyToBeInstalled event is called.

Is there any chance that the service would be restarted before the update is completed?

I haven't had time to go deep into your code, but I'm guessing your service is crashing closed. Try stepping through it with a debugger and figuring out why it's doing this.

Hi again,

I strip my project and I left only the logging and AutomaticUpdater related code, here's what I found so far :

In Initialize() of AutomaticUpdaterBackend class there's this code :

AutoUpdaterInfo = new AutoUpdaterInfo(m_GUID, null);

if (AutoUpdaterInfo.UpdateStepOn == UpdateStepOn.UpdateReadyToInstall){ClosingForInstall = true;..}

In my service OnStart event, after auBackend.Initialize() and AppLoaded(), when I check auBackend.UpdateStepOn it equals UpdateStepOn.Nothing but auBackend.ClosingForInstall equals true. And I see no error when I checked in the event viewer.

So maybe the error is when AutomaticUpdater gets / sets the value in / from the m_GUID file.

To solve my problem I did a quick fix which I hope won't affect to much AutomaticUpdater. When I start my service I change the auBackend.GUID with a new one, so this way, when Initialize() is called ClosingForInstall = false and my code can get executed properly after an update.

I hope we're gonna see 2.6.15 and a fix for this bug soon.

thx for your help!

Hi,

with the latest changes (2011/12/16), the bug has been fixed, this thread can be mark as solved!

thx