private void OnDisconnected(object sender, JsonRpcDisconnectedEventArgs e) { _debuggingLastDisconnectReason = e; _debuggingLastDisconnectCallstack = new StackTrace().ToString(); // tell we got disconnected Disconnected(e); }
protected override void OnDisconnected(JsonRpcDisconnectedEventArgs e) { lock (_gate) { // operation can be cancelled even before initialize is called. // or in the middle of initialize is running _source?.Done(); } }
protected override void OnDisconnected(JsonRpcDisconnectedEventArgs e) { lock (_gate) { // operation can be cancelled even before initialize is called. // or in the middle of initialize is running _source?.Done(); } }
protected override void Disconnected(JsonRpcDisconnectedEventArgs e) { if (e.Reason != DisconnectedReason.Disposed) { // log when this happens LogDisconnectInfo(e, new StackTrace().ToString()); } _shutdownCancellationSource.Cancel(); }
private void OnDisconnected(object sender, JsonRpcDisconnectedEventArgs _) { // clean up cancellation folder try { Directory.Delete(_cancellationFolderPath, recursive: true); } catch (Exception e) when(!e.IsCriticalException()) { // not much we can do. ignore it. } }
private void OnRpcDisconnected(object sender, JsonRpcDisconnectedEventArgs e) { // raise cancellation _cancellationTokenSource.Cancel(); OnDisconnected(e); if (e.Reason != DisconnectedReason.Disposed) { LogError($"Client stream disconnected unexpectedly: {e.Exception?.GetType().Name} {e.Exception?.Message}"); } }
protected void LogDisconnectInfo(JsonRpcDisconnectedEventArgs e, string callstack) { if (e != null) { LogError($"disconnect exception: {e.Description}, {e.Reason}, {e.LastMessage}, {e.Exception?.ToString()}"); } if (callstack != null) { LogError($"disconnect callstack: {callstack}"); } }
private void OnRpcDisconnected(object sender, JsonRpcDisconnectedEventArgs e) { // raise cancellation _cancellationTokenSource.Cancel(); OnDisconnected(e); if (e.Reason != DisconnectedReason.Disposed) { LogError($"Client stream disconnected unexpectedly: {e.Exception?.GetType().Name} {e.Exception?.Message}"); } }
protected override void Disconnected(JsonRpcDisconnectedEventArgs e) { // we don't expect OOP side to disconnect the connection. // Host (VS) always initiate or disconnect the connection. if (e.Reason != DisconnectedReason.LocallyDisposed) { // log when this happens LogDisconnectInfo(e, new StackTrace().ToString()); } _shutdownCancellationSource.Cancel(); }
public async Task JsonRpcClosesStreamAfterDisconnectedEvent() { var server = new Server(); var streams = Nerdbank.FullDuplexStream.CreateStreams(); var clientStream = streams.Item2; // Use wrapped stream to see when the stream is closed and disposed. var serverStream = new WrappedStream(streams.Item1); // Subscribe to disconnected event on the server stream var serverStreamDisconnected = new TaskCompletionSource <object?>(); serverStream.Disconnected += (sender, args) => serverStreamDisconnected.SetResult(null); using (JsonRpc serverRpc = JsonRpc.Attach(serverStream, server)) { // Subscribe to disconnected event on json rpc var disconnectedEventFired = new TaskCompletionSource <JsonRpcDisconnectedEventArgs>(); object?disconnectedEventSender = null; serverRpc.Disconnected += (object?sender, JsonRpcDisconnectedEventArgs e) => { // The stream must not be disposed when the Disconnected even fires Assert.True(serverStream.IsConnected); disconnectedEventSender = sender; disconnectedEventFired.SetResult(e); }; // Send a bad json to the server byte[] badJson = Encoding.UTF8.GetBytes("Content-Length: 1\r\n\r\n{"); await clientStream.WriteAsync(badJson, 0, badJson.Length); // The server must fire disonnected event because bad json must make it disconnect JsonRpcDisconnectedEventArgs args = await disconnectedEventFired.Task.WithCancellation(this.TimeoutToken); Assert.Same(serverRpc, disconnectedEventSender); Assert.NotNull(args); Assert.NotNull(args.Description); Assert.Equal(DisconnectedReason.ParseError, args.Reason); #pragma warning disable CS0618 // Type or member is obsolete Assert.Null(args.LastMessage); #pragma warning restore CS0618 // Type or member is obsolete Assert.NotNull(args.Exception); // Server must dispose the stream now await serverStreamDisconnected.Task.WithCancellation(this.TimeoutToken); Assert.True(serverStream.Disposed); Assert.False(serverStream.IsEndReached); } }
/// <summary> /// Cleanup the server if we encounter a json rpc disconnect so that we can be restarted later. /// </summary> private void JsonRpc_Disconnected(object?sender, JsonRpcDisconnectedEventArgs e) { if (_shuttingDown) { // We're already in the normal shutdown -> exit path, no need to do anything. return; } Logger?.TraceWarning($"Encountered unexpected jsonrpc disconnect, Reason={e.Reason}, Description={e.Description}, Exception={e.Exception}"); ShutdownImpl(); ExitImpl(); }
private void OnDisconnected(object sender, JsonRpcDisconnectedEventArgs e) { _debuggingLastDisconnectReason = e; _debuggingLastDisconnectCallstack = new StackTrace().ToString(); // Don't log info in cases that are common - such as if we dispose the connection or the remote host process shuts down. if (e.Reason != DisconnectedReason.LocallyDisposed && e.Reason != DisconnectedReason.RemotePartyTerminated) { LogDisconnectInfo(e, _debuggingLastDisconnectCallstack); } Disconnected?.Invoke(e); }
private void OnRpcDisconnected(object sender, JsonRpcDisconnectedEventArgs e) { // raise cancellation _shutdownCancellationSource.Cancel(); OnDisconnected(e); if (e.Reason != DisconnectedReason.Disposed) { // this is common for us since we close connection forcefully when operation // is cancelled. use Warning level so that by default, it doesn't write out to // servicehub\log files. one can still make this to write logs by opting in. Log(TraceEventType.Warning, $"Client stream disconnected unexpectedly: {e.Exception?.GetType().Name} {e.Exception?.Message}"); } }
void JsonRpcDisconnected(object sender, JsonRpcDisconnectedEventArgs e) { string errorMessage = GettextCatalog.GetString( "Disconnected from remote PowerShell host. Reason: {0}: {1}", e.Reason, e.Description); scriptingConsole.WriteLine(errorMessage, ScriptingStyle.Error); process.Exited -= Process_Exited; rpc.Disconnected -= JsonRpcDisconnected; messageHandler = null; Exited?.Invoke(this, EventArgs.Empty); }
protected void OnRpcDisconnected(JsonRpcDisconnectedEventArgs e) { try { Log.Debug(e.Exception, $"RPC Disconnected: LastMessage={e.LastMessage} Description={e.Description} Reason={e.Reason} Exception={e.Exception}"); SessionService.SetAgentDisconnected(); EventAggregator?.Publish(new LanguageServerDisconnectedEvent(e.LastMessage, e.Description, e.Reason.ToString(), e.Exception) { IsReloading = isReloading }); } catch (Exception ex) { Log.Error(ex, nameof(OnRpcDisconnected)); } }
void JsonRpcDisconnected(object sender, JsonRpcDisconnectedEventArgs e) { if (e.Exception != null) { Log("JsonRpc disconnection error. Reason: {0}, Description: {1}, Error: {2}", e.Reason, e.Description, e.Exception); } else { Log("JsonRpc disconnection. Reason: {0}, Description: {1}", e.Reason, e.Description); } }
private bool ReportUnlessCanceled(Exception ex, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return(true); } s_debuggingLastDisconnectReason = _debuggingLastDisconnectReason; s_debuggingLastDisconnectCallstack = _debuggingLastDisconnectCallstack; // send NFW to figure out why this is happening ex.ReportServiceHubNFW("RemoteHost Failed"); GC.KeepAlive(_debuggingLastDisconnectReason); GC.KeepAlive(_debuggingLastDisconnectCallstack); return(true); }
private void OnRpcDisconnected(object sender, JsonRpcDisconnectedEventArgs e) { Disconnected?.Invoke(this, EventArgs.Empty); // either service naturally went away since nobody is using // or the other side closed the connection such as closing VS if (e.Reason != DisconnectedReason.LocallyDisposed && e.Reason != DisconnectedReason.RemotePartyTerminated) { // we no longer close connection forcefully. so connection shouldn't go away // in normal situation. if it happens, log why it did in more detail. LogError($@"Client stream disconnected unexpectedly: {nameof(e.Description)}: {e.Description} {nameof(e.Reason)}: {e.Reason} {nameof(e.LastMessage)}: {e.LastMessage} {nameof(e.Exception)}: {e.Exception?.ToString()}"); } }
private void OnRpcDisconnected(object sender, JsonRpcDisconnectedEventArgs e) { // raise cancellation _shutdownCancellationSource.Cancel(); OnDisconnected(e); if (e.Reason != DisconnectedReason.Disposed) { // we no longer close connection forcefully. so connection shouldn't go away // in normal situation. if it happens, log why it did in more detail. LogError($@"Client stream disconnected unexpectedly: {nameof(e.Description)}: {e.Description} {nameof(e.Reason)}: {e.Reason} {nameof(e.LastMessage)}: {e.LastMessage} {nameof(e.Exception)}: {e.Exception?.ToString()}"); } }
private bool ReportUnlessCanceled(Exception ex, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return(true); } s_debuggingLastDisconnectReason = _debuggingLastDisconnectReason; s_debuggingLastDisconnectCallstack = _debuggingLastDisconnectCallstack; // send NFW to figure out why this is happening ReportExtraInfoAsNFW(ex); GC.KeepAlive(_debuggingLastDisconnectReason); GC.KeepAlive(_debuggingLastDisconnectCallstack); return(true); }
public async Task DisconnectedEventIsFired(bool disposeRpc) { var disconnectedEventFired = new TaskCompletionSource <JsonRpcDisconnectedEventArgs>(); // Subscribe to disconnected event object disconnectedEventSender = null; this.serverRpc.Disconnected += (object sender, JsonRpcDisconnectedEventArgs e) => { disconnectedEventSender = sender; disconnectedEventFired.SetResult(e); }; // Close server or client stream. if (disposeRpc) { this.serverRpc.Dispose(); } else { this.serverStream.Dispose(); } JsonRpcDisconnectedEventArgs args = await disconnectedEventFired.Task.WithCancellation(this.TimeoutToken); Assert.Same(this.serverRpc, disconnectedEventSender); Assert.NotNull(args); Assert.NotNull(args.Description); // Confirm that an event handler added after disconnection also gets raised. disconnectedEventFired = new TaskCompletionSource <JsonRpcDisconnectedEventArgs>(); this.serverRpc.Disconnected += (object sender, JsonRpcDisconnectedEventArgs e) => { disconnectedEventSender = sender; disconnectedEventFired.SetResult(e); }; args = await disconnectedEventFired.Task; Assert.Same(this.serverRpc, disconnectedEventSender); Assert.NotNull(args); Assert.NotNull(args.Description); }
private bool ReportUnlessCanceled(Exception ex, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return(true); } s_debuggingLastDisconnectReason = _debuggingLastDisconnectReason; s_debuggingLastDisconnectCallstack = _debuggingLastDisconnectCallstack; // send NFW to figure out why this is happening ex.ReportServiceHubNFW("RemoteHost Failed"); GC.KeepAlive(_debuggingLastDisconnectReason); GC.KeepAlive(_debuggingLastDisconnectCallstack); // we return true here to catch all exceptions from servicehub. // we record them in NFW and convert that to our soft crash exception. return(true); }
private void OnRpcDisconnected(object sender, JsonRpcDisconnectedEventArgs e) { Disconnected(); }
protected override void OnDisconnected(JsonRpcDisconnectedEventArgs e) { _source.Done(); }
protected virtual void OnDisconnected(object sender, JsonRpcDisconnectedEventArgs e) { // do nothing _debuggingLastDisconnectReason = e; _debuggingLastDisconnectCallstack = new StackTrace().ToString(); }
protected override void OnDisconnected(object sender, JsonRpcDisconnectedEventArgs e) { _source.Cancel(); }
private void OnDisconnected(JsonRpcDisconnectedEventArgs e) => Dispose();
private void OnDisconnected(JsonRpcDisconnectedEventArgs e) { _shutdownCancellationSource.Cancel(); }
// Raised when the client process closes the named pipe. private void OnRpcChannelDisconnected(object sender, JsonRpcDisconnectedEventArgs disconnectedEventArgs) { this.TryExit(); }
protected virtual void Disconnected(JsonRpcDisconnectedEventArgs e) { // do nothing }
protected override void OnDisconnected(JsonRpcDisconnectedEventArgs e) { _shutdownCancellationSource.Cancel(); base.OnDisconnected(e); }
protected virtual void OnDisconnected(JsonRpcDisconnectedEventArgs e) { // do nothing }
protected virtual void OnDisconnected(object sender, JsonRpcDisconnectedEventArgs e) { // do nothing }
private void OnRpcDisconnected(object sender, JsonRpcDisconnectedEventArgs e) { Stopped(); }
private void OnDisconnected(JsonRpcDisconnectedEventArgs args) { ConnectEvents(subscription: false); }