Skip to content

Commit 85a4966

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

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-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

+35
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,45 @@ class read1_test : public unit_test::suite
163163

164164
}
165165

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

0 commit comments

Comments
 (0)