From 7839627a0d66ef5419b1b4c3816bece47f74b9f0 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Wed, 13 Sep 2017 20:58:46 -0500 Subject: [PATCH] (GH-1400) API - Ensure one instance of GetChocolatey 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` . --- src/chocolatey/GetChocolatey.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/chocolatey/GetChocolatey.cs b/src/chocolatey/GetChocolatey.cs index c4f0657d46..fc9e929d4b 100644 --- a/src/chocolatey/GetChocolatey.cs +++ b/src/chocolatey/GetChocolatey.cs @@ -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; @@ -40,12 +41,20 @@ namespace chocolatey /// 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()