/// <summary> /// Fire and forget close /// </summary> public override async Task CloseOutputAsync(WebSocketCloseStatus closeStatus, string statusDescription, CancellationToken cancellationToken) { if (_state == WebSocketState.Open) { _state = WebSocketState.Closed; // set this before we write to the network because the write may fail using (MemoryStream stream = _recycledStreamFactory()) { ArraySegment <byte> buffer = BuildClosePayload(closeStatus, statusDescription); WebSocketFrameWriter.Write(WebSocketOpCode.ConnectionClose, buffer, stream, true, _isClient); Events.Log.CloseOutputNoHandshake(_guid, closeStatus, statusDescription); Events.Log.SendingFrame(_guid, WebSocketOpCode.ConnectionClose, true, buffer.Count, true); await WriteStreamToNetwork(stream, cancellationToken); } } else { Events.Log.InvalidStateBeforeCloseOutput(_guid, _state); } // cancel pending reads _internalReadCts.Cancel(); }