Skip to content

Commit

Permalink
[NuGet] If restore failed, try to kill known blocking processes (Conn…
Browse files Browse the repository at this point in the history
…ection Router, CompilerApp, etc...)
  • Loading branch information
xen2 committed Nov 27, 2018
1 parent a92d5b8 commit f0341a7
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions sources/shared/Xenko.NuGetResolver/RestoreHelper.cs
Expand Up @@ -2,6 +2,7 @@
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -119,14 +120,45 @@ public static async Task<(RestoreRequest, RestoreResult)> Restore(ILogger logger
var requests = requestProvider.CreateRequests(restoreArgs).Result;

// Restore the packages
var results = await RestoreRunner.RunWithoutCommit(requests, restoreArgs);
// Commit results so that noop cache works next time
foreach (var result in results)
for (int tryCount = 0; tryCount < 2; ++tryCount)
{
await result.Result.CommitAsync(logger, CancellationToken.None);
try
{
var results = await RestoreRunner.RunWithoutCommit(requests, restoreArgs);

// Commit results so that noop cache works next time
foreach (var result in results)
{
await result.Result.CommitAsync(logger, CancellationToken.None);
}
var mainResult = results.First();
return (mainResult.SummaryRequest.Request, mainResult.Result);
}
catch (Exception e) when (e is UnauthorizedAccessException || e is IOException)
{
// If we have an unauthorized access exception, it means assemblies are locked by running Xenko process
// During first try, kill some known harmless processes, and try again
if (tryCount == 1)
throw;

foreach (var process in new[] { "Xenko.ConnectionRouter" }.SelectMany(Process.GetProcessesByName))
{
try
{
if (process.Id != Process.GetCurrentProcess().Id)
{
process.Kill();
process.WaitForExit();
}
}
catch (Exception)
{
}
}
}
}
var mainResult = results.First();
return (mainResult.SummaryRequest.Request, mainResult.Result);

throw new InvalidOperationException("Unreachable code");
}
}
}
Expand Down

0 comments on commit f0341a7

Please sign in to comment.