Пример #1
0
        private void OnDisconnected(object sender, JsonRpcDisconnectedEventArgs e)
        {
            _debuggingLastDisconnectReason    = e;
            _debuggingLastDisconnectCallstack = new StackTrace().ToString();

            // tell we got disconnected
            Disconnected(e);
        }
Пример #2
0
 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();
     }
 }
Пример #3
0
 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();
     }
 }
Пример #4
0
        protected override void Disconnected(JsonRpcDisconnectedEventArgs e)
        {
            if (e.Reason != DisconnectedReason.Disposed)
            {
                // log when this happens
                LogDisconnectInfo(e, new StackTrace().ToString());
            }

            _shutdownCancellationSource.Cancel();
        }
Пример #5
0
 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.
     }
 }
Пример #6
0
        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}");
            }
        }
Пример #7
0
        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}");
            }
        }
Пример #8
0
        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}");
            }
        }
Пример #9
0
        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);
        }
    }
Пример #11
0
        /// <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();
        }
Пример #12
0
        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);
        }
Пример #13
0
        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}");
            }
        }
Пример #14
0
        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);
        }
Пример #15
0
        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);
     }
 }
Пример #17
0
        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);
        }
Пример #18
0
        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()}");
            }
        }
Пример #19
0
        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()}");
            }
        }
Пример #20
0
        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);
        }
Пример #21
0
    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);
    }
Пример #22
0
        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();
 }
Пример #24
0
 protected override void OnDisconnected(JsonRpcDisconnectedEventArgs e)
 {
     _source.Done();
 }
Пример #25
0
 protected virtual void OnDisconnected(object sender, JsonRpcDisconnectedEventArgs e)
 {
     // do nothing
     _debuggingLastDisconnectReason    = e;
     _debuggingLastDisconnectCallstack = new StackTrace().ToString();
 }
Пример #26
0
 protected override void OnDisconnected(object sender, JsonRpcDisconnectedEventArgs e)
 {
     _source.Cancel();
 }
Пример #27
0
 private void OnDisconnected(JsonRpcDisconnectedEventArgs e)
 => Dispose();
Пример #28
0
 private void OnDisconnected(JsonRpcDisconnectedEventArgs e)
 {
     _shutdownCancellationSource.Cancel();
 }
Пример #29
0
 // Raised when the client process closes the named pipe.
 private void OnRpcChannelDisconnected(object sender, JsonRpcDisconnectedEventArgs disconnectedEventArgs)
 {
     this.TryExit();
 }
Пример #30
0
 protected virtual void Disconnected(JsonRpcDisconnectedEventArgs e)
 {
     // do nothing
 }
Пример #31
0
        protected override void OnDisconnected(JsonRpcDisconnectedEventArgs e)
        {
            _shutdownCancellationSource.Cancel();

            base.OnDisconnected(e);
        }
Пример #32
0
 protected virtual void OnDisconnected(JsonRpcDisconnectedEventArgs e)
 {
     // do nothing
 }
Пример #33
0
 protected virtual void OnDisconnected(object sender, JsonRpcDisconnectedEventArgs e)
 {
     // do nothing
 }
Пример #34
0
 private void OnRpcDisconnected(object sender, JsonRpcDisconnectedEventArgs e)
 {
     Stopped();
 }
Пример #35
0
 private void OnDisconnected(JsonRpcDisconnectedEventArgs args)
 {
     ConnectEvents(subscription: false);
 }