Skip to content

Commit

Permalink
Merge pull request #13908 from heejaechang/fallback
Browse files Browse the repository at this point in the history
make VS not crash when service hub failed to launch
  • Loading branch information
heejaechang authored Sep 20, 2016
2 parents ce98080 + 5140916 commit 93a22e3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ public void Disable()
try
{
instanceTask.Wait(_shutdownCancellationTokenSource.Token);
instanceTask.Result.Shutdown();

// result can be null if service hub failed to launch
instanceTask.Result?.Shutdown();
}
catch (OperationCanceledException)
{
Expand Down Expand Up @@ -151,6 +153,11 @@ private async Task<RemoteHostClient> EnableAsync(CancellationToken cancellationT
// if we reached here, IRemoteHostClientFactory must exist.
// this will make VS.Next dll to be loaded
var instance = await _workspace.Services.GetRequiredService<IRemoteHostClientFactory>().CreateAsync(_workspace, cancellationToken).ConfigureAwait(false);
if (instance == null)
{
return null;
}

instance.ConnectionChanged += OnConnectionChanged;

return instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Remote
internal static class RemoteHostOptions
{
[ExportOption]
public static readonly Option<bool> RemoteHost = new Option<bool>(nameof(InternalFeatureOnOffOptions), nameof(RemoteHost), defaultValue: false,
public static readonly Option<bool> RemoteHost = new Option<bool>(nameof(InternalFeatureOnOffOptions), nameof(RemoteHost), defaultValue: true,
storageLocations: new LocalUserProfileStorageLocation(InternalFeatureOnOffOptions.LocalRegistryPath + nameof(RemoteHost)));

[ExportOption]
Expand Down
15 changes: 13 additions & 2 deletions src/VisualStudio/Core/Next/Remote/RemoteHostClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Host.Mef;
using Roslyn.Utilities;

namespace Microsoft.VisualStudio.LanguageServices.Remote
{
Expand All @@ -13,8 +14,18 @@ internal class RemoteHostClientFactory : IRemoteHostClientFactory
{
public Task<RemoteHostClient> CreateAsync(Workspace workspace, CancellationToken cancellationToken)
{
// this is the point where we can create different kind of remote host client in future (cloud or etc)
return ServiceHubRemoteHostClient.CreateAsync(workspace, cancellationToken);
try
{
// this is the point where we can create different kind of remote host client in future (cloud or etc)
return ServiceHubRemoteHostClient.CreateAsync(workspace, cancellationToken);
}
catch
{
// currently there is so many moving parts that cause, in some branch/drop,
// service hub not to work. in such places (ex, Jenkins), rather than crashing VS
// right away, let VS run without service hub enabled.
return SpecializedTasks.Default<RemoteHostClient>();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ internal class RemoteHostClientFactory : IRemoteHostClientFactory
{
public Task<RemoteHostClient> CreateAsync(Workspace workspace, CancellationToken cancellationToken)
{
// this is the point where we can create different kind of remote host client in future (cloud or etc)
if (workspace.Options.GetOption(RemoteHostClientFactoryOptions.RemoteHost_InProc))
try
{
return InProcRemoteHostClient.CreateAsync(workspace, cancellationToken);
}
// this is the point where we can create different kind of remote host client in future (cloud or etc)
if (workspace.Options.GetOption(RemoteHostClientFactoryOptions.RemoteHost_InProc))
{
return InProcRemoteHostClient.CreateAsync(workspace, cancellationToken);
}

return ServiceHubRemoteHostClient.CreateAsync(workspace, cancellationToken);
return ServiceHubRemoteHostClient.CreateAsync(workspace, cancellationToken);
}
catch
{
return Task.FromResult<RemoteHostClient>(null);
}
}
}
}

0 comments on commit 93a22e3

Please sign in to comment.