Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 8017d87

Browse files
authored
Merge pull request #527 from github/fixes/fix-potential-deadlock
Make sure we don't deadlock loading services
2 parents eb7af2d + b3b5ea6 commit 8017d87

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/GitHub.VisualStudio/GitHubPackage.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Diagnostics;
1515
using System.Threading;
1616
using tasks = System.Threading.Tasks;
17+
using Microsoft.VisualStudio.ComponentModelHost;
1718

1819
namespace GitHub.VisualStudio
1920
{
@@ -75,6 +76,7 @@ public GHClient(IProgram program)
7576
}
7677
}
7778

79+
[NullGuard.NullGuard(NullGuard.ValidationFlags.None)]
7880
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
7981
[ProvideService(typeof(IUIProvider), IsAsyncQueryable = true)]
8082
[ProvideAutoLoad(UIContextGuids.NoSolution)]
@@ -126,11 +128,15 @@ protected override async tasks.Task InitializeAsync(CancellationToken cancellati
126128
}
127129
}
128130

129-
tasks.Task<object> CreateService(IAsyncServiceContainer container, CancellationToken cancellationToken, Type serviceType)
131+
async tasks.Task<object> CreateService(IAsyncServiceContainer container, CancellationToken cancellationToken, Type serviceType)
130132
{
131-
AssemblyResolver.InitializeAssemblyResolver();
132-
var ret = Services.ComponentModel.DefaultExportProvider.GetExportedValueOrDefault<IUIProvider>();
133-
return tasks.Task.FromResult((object)ret);
133+
if (serviceType == null)
134+
return null;
135+
string contract = AttributedModelServices.GetContractName(serviceType);
136+
var cm = await GetServiceAsync(typeof(SComponentModel)) as IComponentModel;
137+
if (cm == null)
138+
return null;
139+
return await tasks.Task.Run(() => cm.DefaultExportProvider.GetExportedValueOrDefault<object>(contract));
134140
}
135141
}
136142
}

0 commit comments

Comments
 (0)