Use handshake_timeout for closing handshake during read operations

Fixes #2999
This commit is contained in:
Mohammad Nejati
2025-04-13 12:47:56 +00:00
committed by Mohammad Nejati
parent 1d8dfae490
commit 1f3c4089ab
2 changed files with 39 additions and 0 deletions

View File

@ -662,6 +662,7 @@ public:
}
impl.change_status(status::closing);
impl.update_timer(this->get_executor());
if(! impl.wr_close)
{

View File

@ -14,6 +14,8 @@
#include <boost/beast/_experimental/test/tcp.hpp>
#include <boost/beast/core/flat_buffer.hpp>
#include <thread>
namespace boost {
namespace beast {
namespace websocket {
@ -163,10 +165,46 @@ public:
}
void
testIssue2999()
{
net::io_context ioc;
// Use handshake_timeout for the closing handshake,
// which can occur in websocket::stream::async_read_some.
stream<test::stream> ws1(ioc);
stream<test::stream> ws2(ioc);
test::connect(ws1.next_layer(), ws2.next_layer());
ws1.async_handshake("test", "/", test::success_handler());
ws2.async_accept(test::success_handler());
test::run(ioc);
flat_buffer b;
ws1.set_option(stream_base::timeout{
std::chrono::milliseconds(50),
stream_base::none(),
false});
// add a close frame to the input
ws1.next_layer().append(string_view{
"\x88\x00", 2});
ws1.async_read(b, test::fail_handler(
beast::error::timeout));
// limit the write buffer so that writing
// the close frame will not complete during
// the call to ioc.run_one()
ws1.next_layer().write_size(1);
ioc.run_one();
ioc.restart();
std::this_thread::sleep_for(
std::chrono::milliseconds(100));
test::run(ioc);
}
void
run() override
{
testTimeout();
testIssue2999();
}
};