Skip to content

Commit

Permalink
(chocolateyGH-1400) API - Ensure one instance of GetChocolatey
Browse files Browse the repository at this point in the history
Surround `Lets.GetChocolatey` with a mutex to ensure only one instance
of `GetChocolatey` is created. There was an issue when accessing the
Chocolatey API, in that you could have multiple threads creating an
instance of `GetChocolatey` at the same time and confusing some of the
setup, causing things to fail. Instead of multiple instances, there
should be a singular instance of `GetChocolatey` .
  • Loading branch information
ferventcoder committed Sep 14, 2017
1 parent c9dbe5d commit 7839627
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/chocolatey/GetChocolatey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace chocolatey
using infrastructure.extractors;
using infrastructure.logging;
using infrastructure.registration;
using infrastructure.synchronization;
using resources;
using Assembly = infrastructure.adapters.Assembly;
using IFileSystem = infrastructure.filesystem.IFileSystem;
Expand All @@ -40,12 +41,20 @@ namespace chocolatey
/// </summary>
public static class Lets
{
public static GetChocolatey GetChocolatey()
private static readonly GetChocolatey _chocolatey = GlobalMutex.enter(() => set_up(), 5);

private static GetChocolatey set_up()
{
add_assembly_resolver();

return new GetChocolatey();
}

public static GetChocolatey GetChocolatey()
{
return _chocolatey;
}

private static ResolveEventHandler _handler = null;

private static void add_assembly_resolver()
Expand Down

0 comments on commit 7839627

Please sign in to comment.