private async Task ConnectProcedure(CancellationToken cancellation) { await _initializationHelper.Initialization; _logger?.LogTrace("Started listening for debug connections."); while (cancellation.ThrowOrContinue()) { try { var client = await _tcpHost.AcceptTcpClientAsync().WithCancellation(cancellation); _logger?.LogInformation($"Debug connection established for ip end-point '{(client.Client.RemoteEndPoint as IPEndPoint).ToString()}'."); var debugSession = new DebugSession(this, client, _serviceProvider, _loggerFactory); if (!_debugSessions.TryAdd(debugSession.Address, debugSession)) { // TODO: Log failure debugSession.Dispose(); } } catch (ObjectDisposedException) when(cancellation.IsCancellationRequested) { return; } catch (OperationCanceledException) when(cancellation.IsCancellationRequested) { return; } catch (Exception exc) { _logger?.LogWarning(exc, "An exception occured while handling a debug connection attempt."); } } }