From 5aa140ca969d191bfea82d866473b7faeb0ef029 Mon Sep 17 00:00:00 2001 From: Johannes Weiss Date: Mon, 21 May 2018 15:32:21 +0100 Subject: [PATCH] websockets: connection closed frame must be flushed Motivation: Because EmbeddedChannel used to treat all writes as flushed the test that tested that we do send out the WebSockets connection close frame didn't actually test the right thing. Now that EmbeddedChannel behaves more realisticly, this test actually fails. This fixes the bug and the test that tests that a WebSockets connection is successfully torn down after an error occured. Modifications: - use `writeAndFlush` to send out the connection close frame. Result: WebSockets connection actually gets closed on error. --- Sources/NIOWebSocket/WebSocketFrameDecoder.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/NIOWebSocket/WebSocketFrameDecoder.swift b/Sources/NIOWebSocket/WebSocketFrameDecoder.swift index 2cc68a208..43f4be4b7 100644 --- a/Sources/NIOWebSocket/WebSocketFrameDecoder.swift +++ b/Sources/NIOWebSocket/WebSocketFrameDecoder.swift @@ -312,8 +312,8 @@ public final class WebSocketFrameDecoder: ByteToMessageDecoder { let frame = WebSocketFrame(fin: true, opcode: .connectionClose, data: data) - _ = ctx.write(self.wrapOutboundOut(frame)).then { - ctx.close() + ctx.writeAndFlush(self.wrapOutboundOut(frame)).whenComplete { + ctx.close(promise: nil) } ctx.fireErrorCaught(error) }