tonyg / racket-rfc6455

RFC 6455 WebSockets support for Racket.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does not properly close the underlying TCP connection if the other side initiates the close handshake

lexi-lambda opened this issue · comments

RFC 6455 § 5.5.1 says:

After both sending and receiving a Close message, an endpoint considers the WebSocket connection closed and MUST close the underlying TCP connection. The server MUST close the underlying TCP connection immediately; the client SHOULD wait for the server to close the connection but MAY close the connection at any time after sending and receiving a Close message, e.g., if it has not received a TCP Close from the server in a reasonable time period.

However, if the remote initiates the close handshake, this library fails to close the TCP sockets. The issue is here:

[(8) ;; close; shutdown
(unless (ws-conn-base-closed? c)
(write-frame (rfc6455-frame #t 8 #"") (ws-conn-base-op c) (rfc6455-conn-mask? c))
(when (>= (bytes-length payload) 2)
(define status (integer-bytes->integer payload #f #t 0 2))
(define reason (bytes->string/utf-8 (subbytes payload 2)))
(set-ws-conn-base-close-status! c status)
(set-ws-conn-base-close-reason! c reason))
(set-ws-conn-base-closed?! c #t))
eof]

While rfc6455-close! explicitly closes the input and output ports, this code path does not, so they are never closed.