Fix race in close frames during reads

This commit is contained in:
Vinnie Falco
2017-02-24 15:10:50 -05:00
parent b9b1b53fda
commit 9554bd105d
2 changed files with 12 additions and 3 deletions

View File

@ -3,6 +3,7 @@
WebSocket
* Fix race in pings during reads
* Fix race in close frames during reads
--------------------------------------------------------------------------------

View File

@ -147,25 +147,33 @@ operator()(error_code ec, bool again)
boost::asio::error::operation_aborted));
return;
}
// fall through
d.ws.wr_block_ = &d;
// [[fallthrough]]
case 1:
// send close frame
BOOST_ASSERT(d.ws.wr_block_ == &d);
d.state = 99;
d.ws.wr_close_ = true;
BOOST_ASSERT(! d.ws.wr_block_);
d.ws.wr_block_ = &d;
boost::asio::async_write(d.ws.stream_,
d.fb.data(), std::move(*this));
return;
case 2:
BOOST_ASSERT(! d.ws.wr_block_);
d.ws.wr_block_ = &d;
d.state = 3;
// The current context is safe but might not be
// the same as the one for this operation (since
// we are being called from a write operation).
// Call post to make sure we are invoked the same
// way as the final handler for this operation.
d.ws.get_io_service().post(
bind_handler(std::move(*this), ec));
return;
case 3:
BOOST_ASSERT(d.ws.wr_block_ == &d);
if(d.ws.failed_ || d.ws.wr_close_)
{
// call handler