bright, fresh software
Downloads  |  Buy

Huge problems with AutomaticUpdateBackend [Solved]

Huge problems with AutomaticUpdateBackend [Solved]

Postby Martin » December 1st, 2011, 6:20 pm

Hi.

I'm having huge problems with AutomaticUpdaterBackend. I use it for updating my windows services. I tried all four modes (Automatic, CheckAndDownload, OnlyCheck and DoNothing), and only Automatic works 100%. The other three all go stuck before the update process has completed.

My system:
- Windows XP Professional SP3
- .NET 4.0 (yes, I use the 4.0 version of AutomaticUpdater.dll)
- wyBuild 2.6.14.0 (the most recent version)


Here are my observations:

Automatic mode (works):
==============
1) I call ForceCheckForUpdate()
2) I get the BeforeCheck event
3) I get the ProgressChanged event (100)
4) I get the BeforeDownloading event
5) I get a row of ProgressChanged events (7% to 100%)
6) I get a BeforeExtracting event
7) I get a row of ProgressChanged events(0% to 83%)
8) I get a ReadyToBeInstalledEvent
9) I call InstallNow()
10) The service rastarts in its new version. Everything OK.

Note: If one of the original files to update are missing, I get an UpdateStepMismatch event an an extra row of ProgressChanged events. I assume this is when the system takes the "all.to.x.x.x.x" update file into use. But
the system still works.


CheckAndDownload mode (with clean files to be updated - works):
===========================================

1) I call ForceCheckForUpdate()
2) I get the BeforeChecking event
3) I get the ProgressChanged (100) event
4) I get the BeforeDownloading event
5) I get a row of ProgressChanged events (6% to 100%)
6) I get the ReadyToBeInstalled event - UpdateStepOn shows: UpdateDownloaded
7) I call InstallNow()
8) I get the BeforeExtracting event
9) I get a row of ProgressChanged events (0%-83%)
10) I get a new ReadyToBeInstalled event - UpdateStepOn shows: UpdateReadyToInstall
11) I call InstallNow() anew
12) The service restarts in its new version. Everything OK.


CheckAndDownload mode with a missing file - DOES NOT WORK:
=========================================

1) I call ForceCheckForUpdate()
2) I get the BeforeChecking event
3) I get the ProgressChanged (100) event
4) I get the BeforeDownloading event
5) I get a row of ProgressChanged events (6% to 100%)
6) I get a ReadyToBeInstalled event - UpdateStepOn shows: UpdateDownloaded
7) I call InstallNow()
8) I get a BeforeExtracting event
9) I get a row of ProcessChanged events (8% to 83%)
10) I get an UpdateStepMismatch event
11) I get a longer row of ProgressChanged events (3% to 100%)
12) I get a new BeforeExtracting event
13) I get a row of ProgressChanged events (0 to 85%)
14) I get a ReadyToBeInstalled event - UpdateStepOn shows: UpdateReadyToInstall
15) I call InstallNow() anew
16) NOTHING HAPPENS.... SYSTEM HAS GONE STUCK! UpdateStepOn keeps on showing UpdateReadyToInstall...


OnlyCheck mode - DOES NOT WORK (not even with clean original files)
=================================================
1) I call ForceCheckForUpdate()
2) I get the BeforeChecking event
3) I get the ProgressChanged (100) event
4) I get the UpdateAvailable event
5) I call InstallNow()
6) I get a BeforeDownloading event
7) I get a row of ProgressChanged events (6% to 100%)
8) I get a BeforeExtracting event
9) I get a row of ProgressChanged events (0% to 83%)
10) I get a ReadyToBeInstalled event - UpdateStepOn shows: UpdateReadyToInstall
11) I call InstallNow() anew
12) NOTHING HAPPENS.... SYSTEM HAS GONE STUCK! UpdateStepOn keeps on showing UpdateReadyToInstall...

DoNothing mode - does NOT work (not even with clean original files)
=================================================
1) I call ForceCheckForUpdate()
2) I get the BeforeChecking event
3) I get the ProgressChanged (100) event
3) I get the UpdateAvailable event
4) I call InstallNow()
5) I get a BeforeDownloading event
6) I get a row of ProgressChanged events (6% to 100%)
7) I get a BeforeExtracting event
8) I get a row of ProgressChanged events (0% to 83%)
9) I get a ReadyToBeInstalled event - UpdateStepOn shows: UpdateReadyToInstall
10) I call InstallNow() anew
11) NOTHING HAPPENS.... SYSTEM HAS GONE STUCK! UpdateStepOn keeps on showing UpdateReadyToInstall...

I would like to use the DoNothing mode, that fires the UpdateAvailable event before downloading, because this way I can the offer the operator not to update this time but simply await the next update to come up instead. All it takes to do this is to call ForceCheckForUpdate( true ) repeatedly after the UpdateAvailable event (instead of InstallNow()) until another update shows up (another UpdateAvailable event will then fire).

Please investigate why CheckOnly and DoNothing modes don't work at all, and why CheckAndDownload mode does not work when original files have been messed with.

- Martin.
Martin
 
Posts: 61
Joined: November 30th, 2009, 4:17 am

Re: Huge problems with AutomaticUpdateBackend

Postby Wyatt » December 1st, 2011, 7:52 pm

We're going to look into this either tonight or sometime later tomorrow afternoon. I'll get back to you.
User avatar
Wyatt
Site Admin
 
Posts: 2558
Joined: July 11th, 2007, 10:30 pm
Location: New Hampshire

Re: Huge problems with AutomaticUpdateBackend

Postby Martin » December 2nd, 2011, 1:38 am

I discovered that I forgot to call AppLoaded() after my call to Initialize(). However, I added the call and ran the program again (using DoNoting mode) but with the same results.

It's a bit difficult to replicate each try because of wyUpdate's caching mechanism - most often I have to run the test twice in order to get the downloading and file extraction to happen. If updates are cached from an earlier non-completed update process, updating usually happens almost instantly and without problems (=getting the UpdateReadyToBeInstalled event very quickly, and InstallNow() then completes the job).

-Martin.
Martin
 
Posts: 61
Joined: November 30th, 2009, 4:17 am

Re: Huge problems with AutomaticUpdateBackend

Postby Wyatt » December 2nd, 2011, 10:56 am

Well, forgetting AppLoaded() will cause a lot of problems (because it sets up the AutomaticUpdater state and calls the correct events). But I'll check into the DoNothing problem.
User avatar
Wyatt
Site Admin
 
Posts: 2558
Joined: July 11th, 2007, 10:30 pm
Location: New Hampshire

Re: Huge problems with AutomaticUpdateBackend

Postby Wyatt » December 2nd, 2011, 5:48 pm

We can't reproduce this here. In all cases the updating works fine. Can you send me a simple service that can reproduce this behavior? Send it to wyatt@wyday.com


11) NOTHING HAPPENS.... SYSTEM HAS GONE STUCK! UpdateStepOn keeps on showing UpdateReadyToInstall...


Does your service stop? Is wyUpdate running in the task manager? Or does it close?
User avatar
Wyatt
Site Admin
 
Posts: 2558
Joined: July 11th, 2007, 10:30 pm
Location: New Hampshire

Re: Huge problems with AutomaticUpdateBackend

Postby Martin » December 5th, 2011, 3:56 am

Good morning Wyatt, and thank you very much for your efforts so far.

I will send you a small service that does nothing, and that reproduces the behaviour. An to your questions:

No, the service doesn't stop.

I tried the scenario again this morning, this time the sytem went stuck in state "ExtractingUpdate". Last event recevied was "BeforeExtracting". wyUpdate.exe keeps running in TaskManager (with 00% CPU load).
Martin
 
Posts: 61
Joined: November 30th, 2009, 4:17 am

Re: Huge problems with AutomaticUpdateBackend

Postby Wyatt » December 5th, 2011, 2:38 pm

Hey Martin,

There's quite a bit of code to work through here -- it'll take me a while to find the root cause of the problem. My instincts tell me (and from what you're saying on our forum) it looks like you're not handling an event from the AutomaticUpdater correctly.

Here's what I mean. From what you say, when the AU UpdateType is set to "Automatic" then everything works fine. The "Automatic" UpdateType is only different from the other UpdateTypes in that the AU handles taking the next step automatically (instead of forcing you to call the correct functions).


That being said there might be a bug in the AutomaticUpdater. I'll only know once I work through your code. This could take several days. If you want a quicker resolution to this problem here's how you can handle it:

Get the AutomaticUpdater source code (http://wyday.com/wybuild/help/automatic-updates/ ). Add your project to the VS Solution, and step through your code in a debugger and see why it works with UpdateType = Automatic, and not the other UpdateTypes.


That's what I'll be doing a little bit later.
User avatar
Wyatt
Site Admin
 
Posts: 2558
Joined: July 11th, 2007, 10:30 pm
Location: New Hampshire

Re: Huge problems with AutomaticUpdateBackend

Postby Martin » December 5th, 2011, 3:36 pm

Hi Wyatt.

I'm sorry for stealing so much of your time with my problem. You mention that I probably do not handle an event from AU correctly. Could you tell me in a few words what correct handling should be?

I my code I have attached event handlers to every single AU event I could find, but - apart from UpdateAvailable and UpdateReadyToInstall - the event handlers only output debug messages. The two mentioned event handlers basically only cause InstallNow() to be called in order to get the update process completed. Shouldn't it suffice just to call InstallNow() in response the the two events?

However, in my code InstallNow() is called from a dfferent thread from the one calling ForceCheckForUpdate() and from the one fireing the events - is that a problem? I'm at home now, but tomorrow I will cut down my code even more and send it to you anew, so you won't have more code than necessary to go through. Wouldn't that be nice? :-)

- Martin
Martin
 
Posts: 61
Joined: November 30th, 2009, 4:17 am

Re: Huge problems with AutomaticUpdateBackend

Postby Wyatt » December 5th, 2011, 3:47 pm

However, in my code InstallNow() is called from a dfferent thread from the one calling ForceCheckForUpdate() and from the one fireing the events - is that a problem?


This sounds like it might be the problem. We're changing how services are stopped in AU 2.6.15. Right now, we call Environment.Exit(0); to kill the service. In 2.6.15 we're going to call ServiceBase.Stop(). This should fix some of the threading issues involved with services.

In the meantime try calling InstallNow() with the main service thread.
User avatar
Wyatt
Site Admin
 
Posts: 2558
Joined: July 11th, 2007, 10:30 pm
Location: New Hampshire

Re: Huge problems with AutomaticUpdateBackend

Postby Martin » December 6th, 2011, 2:38 pm

Hi Wyatt.

I have done a lot of debuggung with your source code and I have now found out what goes wrong. I have also found a way to solve it.

The problem lies in the AutomaticUpdater.dll (.NET4 version).

The AutomaticUpdaterBackend makes use of a BackgroundWorker object to get update steps done in the background in a separate thread.

When my test service goes stuck while updating it is because the BackgroundWorker object at a certain step in the update process keeps holding its IsBusy property true even though the code in the bw_DoWork event handler has completed. While debugging I also found that that the bw_RunWorkerCompleted event handler was never called in that case.

That puzzled me very much because I could follow the completion of the code in the bw_DoWork event handler, and according to Microsoft's documentation to the BackgroundWorker class this should indeed cause the RunWorkerCompleted event to be fired (and the IsBusy property to go false). But it didn't.

Then I did quite a bit of googling and finally I came across this thread:

http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/a4c919a6-b6cc-4a4f-bda7-c7585a57b4eb
(title: "Background Worker not firing RunWorkerCompleted event" )

After some experimenting I was able to solve the problem by modifiying the UpdateHelper class this way:

* Instead of reusing the same BackgroundWorker instance over and over I now create a new instance for each job to be run (and remember to properly get rid of the old one).
* Prior to each creation of a new BackgroundWorker instance (and setting up event handlers) I call System.Windows.Forms.Application.DoEvents(); (inspired by my google search)
* Right after creation I remember to set bw.WorkerReportsProgress=true; and bw.WorkerSupportsCancellation=true;
* In the bw_DoWork event handler i also added a call to System.Windows.Forms.Application.DoEvents() as the very last statement.

I encapsulated the recreaton of BackgrondWorker instances into the follwing method:

private void RecreateBackgroundWorker()
{
if (bw != null)
{
bw.DoWork -= bw_DoWork;
bw.RunWorkerCompleted -= bw_RunWorkerCompleted;
bw.Dispose();
bw = null;
}

if (bw == null)
{
System.Windows.Forms.Application.DoEvents();
bw = new BackgroundWorker();
bw.DoWork += bw_DoWork;
bw.RunWorkerCompleted += bw_RunWorkerCompleted;
bw.WorkerReportsProgress = true;
bw.WorkerSupportsCancellation = true;
}
}

which I call from within the SendAsync(...) method - I'm sure you get the picture.

Result: NOW EVERYTHING WORKS!

New questions:
- Is there a risk that my calls to System.Windows.Forms.Application.DoEvents() have unwanted side effects?
- Would you consider implementing this change in the next version of AutomaticUpdater?


-Martin
Martin
 
Posts: 61
Joined: November 30th, 2009, 4:17 am

Next

Return to wyBuild, wyUpdate, & AutomaticUpdater Support