Skip to content

Commit

Permalink
Clients should not close the TCP connection
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 23, 2024
1 parent df44f88 commit f184b69
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Sources/HummingbirdWebSocket/WebSocketHandler.swift
Original file line number Diff line number Diff line change
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 f184b69

Please sign in to comment.