Squirrel.Windows: Squirrel leaking mutex?

Sometimes on update I get the guy below. Update completes successfully, just this message dialog is shown.

Message: An unhandled exception of type ‘System.Threading.AbandonedMutexException’ occurred in Squirrel.dll Additional information: Leaked a Mutex!

Squirrel.dll!Squirrel.SingleGlobalInstance.~SingleGlobalInstance() Unknown

The update code is almost out of the box:

Task.Run(async () =>
            {
                try
                {
                    using (var mgr = new UpdateManager(@"SOMEWHERE"))
                    {
                        var re = await mgr.UpdateApp();
                        if(re != null)
                        {
                            UpdateManager.RestartApp();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            });

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 31 (6 by maintainers)

Most upvoted comments

for UpdateManager.GitHubUpdateManager, dispose the reult works for me mgr = UpdateManager.GitHubUpdateManager(WPFView.Properties.Settings.Default.UpdatePath); using (var result = await mgr) { await result.UpdateApp(); } the code in the document doesn’t work using (var mgr = UpdateManager.GitHubUpdateManager("https://github.com/myuser/myapp")) { await mgr.Result.UpdateApp(); }

hi,
I have the same issue but a found a curious solution.

exemple code :

public async Task<bool> Check() { using (this.updater = new UpdateManager(this._url.ToString())) { var val = await this._updater.CheckForUpdate(); } //some code return result; }

throw mutex exception;

But whith this code not; ` public async Task<bool> Check() {

        using (this.updater = new UpdateManager(this._url.ToString()))
        {
           var val = await this._updater.CheckForUpdate();
        }
        //some code
        this._updater = null;
        GC.WaitForFullGCComplete();
        return result;
    }`

I don’t have any exception throw

@asfarley Yep, you’ve got the same problem. Here’s one straightforward way to solve it:

public async Task UpdateIfAvailable() {
    updateInProgress = RealUpdateIfAvailable();
    await updateInProgress;
}

public async Task WaitForUpdatesOnShutdown() {
    // We don't actually care about errors here, only completion
    await updateInProgress.ContinueWith(ex => {}); 
}

Task updateInProgress = Task.FromResult(true);
private async Task RealUpdateIfAvailable() {
    lastUpdateCheck = DateTime.Now;
    _logger.Debug("Checking remote server for update.");
    try {
        using (var mgr = new UpdateManager("XXXXXXX")) {
            await mgr.UpdateApp();
        }
    } catch (Exception ex) {
        _logger.Debug(ex.Message);
    }
}


/// Now, in your shutdown code

async void ShutdownTheApp() {
    allTheWindows.ForEach(x => x.Close());
    await WaitForUpdatesOnShutdown();

    Application.Quit();
}

@longlostbro The problem is that it’s highly dependent on your application, but in general, if your app’s Quit menu doesn’t have logic for “If the update is running, wait on it before we exit”, this is probably what’s happening.

Every example I’ve found of this is user error, you’re checking for updates but closing the app before it completes. This is a bug in your app - killing the app while updates are applying is bad.

If anyone can prove that they are Doing It Right and they’re still hitting this bug, please create a new bug

OK - well as I say I just lifted the basics from the GitHub manager docs.

Is there a more concrete example of how to use Squirrel? I’m now not using the Easy Mode since I want to be able to update my basic UI with a message if an update is available, or is installing. If you know of any .net apps that do this and are Open Source I’d be grateful for a pointer in the right direction 😃.

Additionally, I don’t want to clog up your issue(s) with my specific implementation questions - so if there’s a better place for me to go get help with that then feel free to point me there also 👍