-
Notifications
You must be signed in to change notification settings - Fork 641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better document websocket::stream::async_close
and teardown relationship
#2730
Comments
I have a question related to this. When |
What happens to the tcp socket depends on the other side. I think It sends the close frame to the other side, so the server might decide to just drop the connection at this point without a response (unlikely, but possible) in which case you'd get an error from the tcp layer. This would also apply to your second question. But ideally, you'd send the close-frame to the server, which then initialized an ordered teardown, then tears down the ssl layer (which google usually skips) and then closes the socket. |
I have refactored my server logic to not depend on I now also destroy the |
Oops, I think that would violate this note from the
...as the The Asio sockets are more robust in this respect, as calling |
websocket::stream::async_close
are not documentedwebsocket::stream::async_close
and teardown relationship
As requested by the author here, I'm bumping this issue so that the relationship between
|
I've also been confused by this, but wrote some code that appeared to work well for a few years. But then beast::ssl_stream was deprecated and it started crashing in some cases. At least, in new code, it looks like closing a |
The new changes shouldn't affect this behavior. Did you make any other changes to your code? In what scenario does your code crash? Could you provide a minimal reproducible example? |
This snippet is the code that triggers the crash, at least in some scenarios It throws It appears that we might be able to just drop all this extra shutdown and close stuff? void WebsocketClient::on_close_frame_sent(boost::system::error_code ec)
{
if (ec) {
// We could not send a close frame => the connection is not
// responsive => there is not going to be a clean teardown.
boost::beast::get_lowest_layer(*stream_).close();
return;
}
auto & ssl = stream_->next_layer();
ssl.next_layer().expires_at(timeout_at_);
ssl.async_shutdown(
[this, self = shared_from_this()](const boost::system::error_code & ec) {
boost::beast::get_lowest_layer(*stream_).close();
});
} |
This is probably due to this bug: boostorg/beast#2925. It's fixed in Boost 1.87.0.
You only need to initiate a websocket::stream::async_close. It handles everything for you. By the way, this is only necessary if you are the one initiating the close operation. If the peer initiates the close, |
Is that only true if you use a I have tried to read the documentation mentioned by @ecorm and agree that the documentation should be clear about this stuff. =) |
Sorry, which part are you referring to? |
The part here:
The |
Yes, this is independent of the type of underlying stream you use with websocket::async_teardown is a customization point that |
That's great news. It would be great if the documentation could be equally clear =) |
Version of Beast: Boost 1.83.0
The documentation for
websocket::stream::async_close
does not specify what happens to the underlying TCP socket in both success and error paths (same goes forwebsocket::stream::close
).I'm guessing the teardown customization point has something to do with this, but there is no mention of it in the
async_close
documentation.In particular, I need to know if the underlying TCP socket is closed when
websocket::stream::async_close
completes either successfully or with an error.I know that I can do
if (websocket_.next_layer().is_closed())
in the completion handler to find out at runtime, but I'd still like to know the behavior.ADDENDUM:
websocket::stream::async_close
also does not document whetheris_open() == false
is a postcondition whether or not the operation succeeds. I would expectis_open() == false
to always be a postcondition whether or not it succeeds.The text was updated successfully, but these errors were encountered: