Skip to content
Permalink
Browse files

[NuGet] If restore failed, try to kill known blocking processes (Conn…

…ection Router, CompilerApp, etc...)
  • Loading branch information
xen2 committed Nov 27, 2018
1 parent a92d5b8 commit f0341a72d5ee359b36ffcad8dc18d009689ff232
Showing with 38 additions and 6 deletions.
  1. +38 −6 sources/shared/Xenko.NuGetResolver/RestoreHelper.cs
@@ -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;
@@ -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");
}
}
}

0 comments on commit f0341a7

Please sign in to comment.
You can’t perform that action at this time.