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?
Asked
Active
Viewed 155 times
1

sehe
- 374,641
- 47
- 450
- 633

Кирилл Волков
- 372
- 1
- 11
1 Answers
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
-
Everything is executed on the single thread – Кирилл Волков Sep 14 '22 at 12:53
-
Just to check where and how do you run the io_context? – sehe Sep 14 '22 at 12:59
-
If we skip the details of implementation, context is created in the main function and the rest of the code is called inside post function – Кирилл Волков Sep 14 '22 at 13:03
-
There was just 1 thing I wanted to check: _where_ do you `run()` it? I'm assuming directly in main. – sehe Sep 14 '22 at 13:10
-
1Yes, you are right – Кирилл Волков Sep 14 '22 at 13:29