@@ -194,7 +194,7 @@ public struct WebSocketCloseFrame: Sendable {
194194 // Close handshake. Wait for responding close or until inbound ends
195195 while let frame = try await inboundIterator. next ( ) {
196196 if case . connectionClose = frame. opcode {
197- try await self . receivedClose ( frame)
197+ await self . receivedClose ( frame)
198198 // only the server can close the connection, so clients
199199 // should continue reading from inbound until it is closed
200200 if type == . server {
@@ -319,14 +319,16 @@ public struct WebSocketCloseFrame: Sendable {
319319 }
320320 }
321321
322- func receivedClose( _ frame: WebSocketFrame ) async throws {
322+ func receivedClose( _ frame: WebSocketFrame ) async {
323323 guard frame. reservedBits. isEmpty else {
324- try await self . close ( code: . protocolError, reason: nil )
324+ // ignore errors from sending close as the other side may have closed the connection already
325+ try ? await self . close ( code: . protocolError, reason: nil )
325326 return
326327 }
327328 switch self . stateMachine. receivedClose ( frameData: frame. unmaskedData, validateUTF8: self . configuration. validateUTF8) {
328329 case . sendClose( let errorCode) :
329- try await self . sendClose ( code: errorCode, reason: nil )
330+ // ignore errors from sending close as the other side may have closed the connection already
331+ try ? await self . sendClose ( code: errorCode, reason: nil )
330332 // Only server should initiate a connection close. Clients should wait for the
331333 // server to close the connection when it receives the WebSocket close packet
332334 // See https://www.rfc-editor.org/rfc/rfc6455#section-7.1.1
0 commit comments