1

I am using beast for implementation of HTTPS Client. In order to make the handshake I call async_handshake. But if I try to shutdown the stream via async_shutdown, I receive the following assert: boost::beast::detail::stream_base::pending_guard::pending_guard(bool&): Assertion `! b_' failed. Is there a way to correctly shutdown the stream during the handshake?

sehe
  • 374,641
  • 47
  • 450
  • 633

1 Answers1

0

As far as I can tell the assertion means that a read/write operation is in progress. Make sure you synchronize access to the stream object using a (implicit) strand.

If you have only one thread, you should already have it. Otherwise, post to the strand executor, e.g. instead of

stream_.async_shutdown(handler);

Do something like

boost::asio::post(stream_.get_executor(),
     [self] { self->stream_.async_shutdown(handler); });

If the containing class has shared ownership you would have auto self = shared_from_this();. Otherwise self could just be this.

More background on where and why of strands: Asio docs and Why do I need strand per connection when using boost::asio?

sehe
  • 374,641
  • 47
  • 450
  • 633