Ejemplo n.º 1
0
        private async Task PerformDisconnectAsyncCore(string connectionId, bool abortOnClose)
        {
            var connection = _clientConnectionManager.RemoveClientConnection(connectionId);

            if (connection != null)
            {
                // remove it from the list to prevent it from called multiple times
                _connectionIds.TryRemove(connectionId, out _);

                // In normal close, service already knows the client is closed, no need to be informed.
                connection.AbortOnClose = abortOnClose;

                // We're done writing to the application output
                connection.Application.Output.Complete();

                var app = connection.ApplicationTask;

                // Wait on the application task to complete
                if (!app.IsCompleted)
                {
                    connection.CancelApplication(_closeTimeOutMilliseconds);
                    await app;
                }

                Log.ConnectedEnding(Logger, connectionId);
            }
        }
Ejemplo n.º 2
0
        private async Task PerformDisconnectAsyncCore(string connectionId, bool abortOnClose)
        {
            var connection = _clientConnectionManager.RemoveClientConnection(connectionId);

            if (connection != null)
            {
                // remove it from the list to prevent it from called multiple times
                _connectionIds.TryRemove(connectionId, out _);

                // In normal close, service already knows the client is closed, no need to be informed.
                connection.AbortOnClose = abortOnClose;

                // We're done writing to the application output
                connection.Application.Output.Complete();

                var app = connection.ApplicationTask;

                // Wait on the application task to complete
                if (!app.IsCompleted)
                {
                    try
                    {
                        using (var delayCts = new CancellationTokenSource())
                        {
                            var resultTask =
                                await Task.WhenAny(app, Task.Delay(CloseApplicationTimeout, delayCts.Token));

                            if (resultTask != app)
                            {
                                // Application task timed out and it might never end writing to Transport.Output, cancel reading the pipe so that our ProcessOutgoing ends
                                connection.Application.Input.CancelPendingRead();
                                Log.ApplicationTaskTimedOut(Logger);
                            }
                            else
                            {
                                delayCts.Cancel();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.ApplicationTaskFailed(Logger, ex);
                    }
                }

                Log.ConnectedEnding(Logger, connectionId);
            }
        }
Ejemplo n.º 3
0
 private void RemoveClientConnection(string connectionId)
 {
     _clientConnectionManager.RemoveClientConnection(connectionId);
     _connectionIds.TryRemove(connectionId, out _);
 }
Ejemplo n.º 4
0
 private ClientConnectionContext RemoveClientConnection(string connectionId)
 {
     _connectionIds.TryRemove(connectionId, out _);
     return(_clientConnectionManager.RemoveClientConnection(connectionId));
 }