From 7b1ed3f360a23851c7c096f3994f8932156050a0 Mon Sep 17 00:00:00 2001 From: Heejae Chang Date: Fri, 15 Sep 2017 14:36:04 -0700 Subject: [PATCH] made timeout to 7 days so that sleep won't affect it. for master, we should create sleep aware timer to check timeout. for now just 7 days. also made crash to NFW and info bar. --- .../Remote/RemoteHostOptions.cs | 2 +- .../Next/Remote/ServiceHubRemoteHostClient.cs | 54 ++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/VisualStudio/Core/Def/Implementation/Remote/RemoteHostOptions.cs b/src/VisualStudio/Core/Def/Implementation/Remote/RemoteHostOptions.cs index 327457d640f..b19441281e4 100644 --- a/src/VisualStudio/Core/Def/Implementation/Remote/RemoteHostOptions.cs +++ b/src/VisualStudio/Core/Def/Implementation/Remote/RemoteHostOptions.cs @@ -36,7 +36,7 @@ internal static class RemoteHostOptions // normally response time is within 10s ms. at most 100ms. if priority is changed to "Normal", most of time 10s ms. [ExportOption] public static readonly Option RequestServiceTimeoutInMS = new Option( - nameof(InternalFeatureOnOffOptions), nameof(RequestServiceTimeoutInMS), defaultValue: 10 * 60 * 1000, + nameof(InternalFeatureOnOffOptions), nameof(RequestServiceTimeoutInMS), defaultValue: 7 * 24 * 60 * 60 * 1000 /* 7 day */, storageLocations: new LocalUserProfileStorageLocation(InternalFeatureOnOffOptions.LocalRegistryPath + nameof(RequestServiceTimeoutInMS))); // This options allow users to restart OOP when it is killed by users diff --git a/src/VisualStudio/Core/Next/Remote/ServiceHubRemoteHostClient.cs b/src/VisualStudio/Core/Next/Remote/ServiceHubRemoteHostClient.cs index d920ab0af64..efa68630b9c 100644 --- a/src/VisualStudio/Core/Next/Remote/ServiceHubRemoteHostClient.cs +++ b/src/VisualStudio/Core/Next/Remote/ServiceHubRemoteHostClient.cs @@ -9,6 +9,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.Execution; +using Microsoft.CodeAnalysis.Extensions; using Microsoft.CodeAnalysis.Internal.Log; using Microsoft.CodeAnalysis.Remote; using Microsoft.ServiceHub.Client; @@ -192,10 +193,22 @@ private void OnRpcDisconnected(object sender, JsonRpcDisconnectedEventArgs e) // wait for retry_delayInMS before next try await Task.Delay(retry_delayInMS, cancellationToken).ConfigureAwait(false); + + ReportTimeout(start); } // operation timed out, more than we are willing to wait - throw new TimeoutException("RequestServiceAsync timed out"); + ShowInfoBar(); + + // create its own cancellation token and throw it + using (var ownCancellationSource = new CancellationTokenSource()) + { + ownCancellationSource.Cancel(); + ownCancellationSource.Token.ThrowIfCancellationRequested(); + } + + // unreachable + throw ExceptionUtilities.Unreachable; } private static async Task RequestServiceAsync( @@ -264,6 +277,14 @@ private static int ReportDetailInfo(IFaultUtility faultUtility) try { + // add service hub process. + // we will record dumps for all service hub processes + foreach (var p in Process.GetProcessesByName("ServiceHub.RoslynCodeAnalysisService32")) + { + // include all remote host processes + faultUtility.AddProcessDump(p.Id); + } + var logPath = Path.Combine(Path.GetTempPath(), "servicehub", "logs"); if (!Directory.Exists(logPath)) { @@ -303,5 +324,36 @@ private static bool ReportNonIOException(Exception ex) // catch all exception. not worth crashing VS. return true; } + + private static readonly TimeSpan s_reportTimeout = TimeSpan.FromMinutes(10); + private static bool s_timeoutReported = false; + + private static void ReportTimeout(DateTime start) + { + // if we tried for 10 min and still couldn't connect. NFW some data + if (!s_timeoutReported && (DateTime.UtcNow - start) > s_reportTimeout) + { + s_timeoutReported = true; + + // report service hug logs along with dump + WatsonReporter.Report("RequestServiceAsync Timeout", new Exception("RequestServiceAsync Timeout"), ReportDetailInfo); + } + } + + private static bool s_infoBarReported = false; + + private static void ShowInfoBar() + { + // use info bar to show warning to users + if (CodeAnalysis.PrimaryWorkspace.Workspace != null && !s_infoBarReported) + { + // do not report it multiple times + s_infoBarReported = true; + + // use info bar to show warning to users + CodeAnalysis.PrimaryWorkspace.Workspace.Services.GetService()?.ShowGlobalErrorInfo( + ServicesVSResources.Unfortunately_a_process_used_by_Visual_Studio_has_encountered_an_unrecoverable_error_We_recommend_saving_your_work_and_then_closing_and_restarting_Visual_Studio); + } + } } } -- GitLab