Repository navigation
Conversation
close() waited for the peer's Close reply with a read timeout that applied to each read, so a peer that kept sending other frames, or sent one frame a byte at a time, held close() for as long as it liked. Bound the wait as a whole. close() sets the stream's max timeout, which shortens each wait to what is left, and stops reading frames at the deadline, which matters when the peer keeps the socket full and no wait happens at all. WebSocketSSLStream gains set_max_timeout(), the one stream a WebSocket uses that lacked it. A read() running on another thread when close() is called still waits for the reply up to its own read timeout, as documented. The docs now say how to bound it.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An alternative to #2667 for comparison.
WebSocket::close() waits for the peer's Close reply for
CPPHTTPLIB_WEBSOCKET_CLOSE_TIMEOUT_SECOND, but the timeout applied to each
read. A peer that kept sending other frames, or sent one frame a byte at a
time, held close() for as long as it liked.
This bounds close()'s own wait as a whole, with the existing
Stream::set_max_timeout() (the mechanism that bounds the request head) and
a deadline check in the frame loop:
that trickles a frame.
happens at all.
that lacked it.
How it differs from #2667:
To do that portably it makes every WebSocket read wait in 100 ms slices,
also by default and on connections that never call close(). Here that case
stays as currently designed and documented: the other thread's read() waits
up to its own read timeout. README-websocket.md and the graceful shutdown
cookbook page now say how to bound it with set_read_timeout().
is built with a 1 second close timeout, so they take about 1 s each instead
of the real 5 s.
Tests (WebSocketCloseTest in test_websocket_heartbeat): a raw ws and wss
client that never answers the server's close() and either floods empty Pings
or sends a 20-byte Ping a byte at a time. Each fails without the piece it
covers: the flood without the deadline check, the trickle without the max
timeout, and the wss trickle without WebSocketSSLStream::set_max_timeout().