Skip to content

Commit

Permalink
Clients should not close the TCP connection (#44)
Browse files Browse the repository at this point in the history
Instead they should wait for the server to initiate the connection close
  • Loading branch information
adam-fowler committed Mar 26, 2024
1 parent df44f88 commit a82530e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Sources/HummingbirdWebSocket/WebSocketHandler.swift
Expand Up @@ -194,7 +194,12 @@ actor WebSocketHandler: Sendable {
var buffer = context.allocator.buffer(capacity: 2)
buffer.write(webSocketErrorCode: code)
try await outbound.write(frame: .init(fin: true, opcode: .connectionClose, data: buffer))
outbound.finish()
// Only server should initiate a connection close. Clients should wait for the
// server to close the connection when it receives the WebSocket close packet
// See https://www.rfc-editor.org/rfc/rfc6455#section-7.1.1
if self.type == .server {
outbound.finish()
}
}
}

Expand Down

0 comments on commit a82530e

Please sign in to comment.