private async Task DequeueAsync() { await _locker.WaitAsync(); try { while (_frames.TryDequeue(out var frame)) { var completeWriteBack = frame.Size == 0; _log.Verbose("ConnectId: {connectionId}. Dequeue frame {frameSize}", frame.ConnectionId, frame.Size); try { await _writer.WriteAsync(frame); } catch (Exception e) { var se = e.Find <SocketException>(x => x.ErrorCode.In(10004, 10054)); if (se != null) { _log.Information("ConnectionId: {connectionId}. Socket canceled with code {errorCode} during pending read: {errorMessage}", frame.ConnectionId, se.ErrorCode, se.Message); } else { _log.Error(e, "ConnectionId: {connectionId}. Unable to write to multiplexed connection", frame.ConnectionId); } completeWriteBack = true; } if (completeWriteBack) { _completeLocalWriter(frame.ConnectionId); } } } finally { _locker.Release(); } }