Skip to content

Commit 645d159

Browse files
committed
Use handshake_timeout for closing handshake during read operations
Fixes #2999
1 parent 1d8dfae commit 645d159

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

include/boost/beast/websocket/impl/read.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ class stream<NextLayer, deflateSupported>::read_some_op
662662
}
663663

664664
impl.change_status(status::closing);
665+
impl.update_timer(this->get_executor());
665666

666667
if(! impl.wr_close)
667668
{

test/beast/websocket/read1.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <boost/beast/_experimental/test/tcp.hpp>
1515
#include <boost/beast/core/flat_buffer.hpp>
1616

17+
#include <thread>
18+
1719
namespace boost {
1820
namespace beast {
1921
namespace websocket {
@@ -163,10 +165,46 @@ class read1_test : public unit_test::suite
163165

164166
}
165167

168+
void
169+
testIssue2999()
170+
{
171+
net::io_context ioc;
172+
173+
// Use handshake_timeout for the closing handshake,
174+
// which can occur in websocket::stream::async_read_some.
175+
stream<test::stream> ws1(ioc);
176+
stream<test::stream> ws2(ioc);
177+
test::connect(ws1.next_layer(), ws2.next_layer());
178+
ws1.async_handshake("test", "/", test::success_handler());
179+
ws2.async_accept(test::success_handler());
180+
test::run(ioc);
181+
182+
flat_buffer b;
183+
ws1.set_option(stream_base::timeout{
184+
std::chrono::milliseconds(50),
185+
stream_base::none(),
186+
false});
187+
// add a close frame to the input
188+
ws1.next_layer().append(string_view{
189+
"\x88\x00", 2});
190+
ws1.async_read(b, test::fail_handler(
191+
beast::error::timeout));
192+
// limit the write buffer so that writing
193+
// the close frame will not complete during
194+
// the call to ioc.run_one()
195+
ws1.next_layer().write_size(1);
196+
ioc.run_one();
197+
ioc.restart();
198+
std::this_thread::sleep_for(
199+
std::chrono::milliseconds(100));
200+
test::run(ioc);
201+
}
202+
166203
void
167204
run() override
168205
{
169206
testTimeout();
207+
testIssue2999();
170208
}
171209
};
172210

0 commit comments

Comments
 (0)