@@ -44,6 +44,13 @@ auto const kDefaultInitialReconnectDelay = std::chrono::seconds(1);
44
44
// Maximum duration between backoff attempts.
45
45
auto const kDefaultMaxBackoffDelay = std::chrono::seconds(30 );
46
46
47
+ // When we shut down the SSL stream using async_shutdown operation, it
48
+ // appears that the completion handler isn't invoked for about 5 minutes. Either
49
+ // we or the server are misbehaving here. In any case, there is no need to wait
50
+ // 5 minutes, we should give a couple seconds to receive a valid response or
51
+ // else stop waiting.
52
+ auto const kShutdownTimeout = std::chrono::seconds(5 );
53
+
47
54
static boost::optional<net::ssl::context&> ToOptRef (
48
55
std::optional<net::ssl::context>& maybe_val) {
49
56
if (maybe_val) {
@@ -341,15 +348,17 @@ class FoxyClient : public Client,
341
348
void do_shutdown (std::function<void ()> completion) {
342
349
shutting_down_ = true ;
343
350
backoff_timer_.cancel ();
351
+ session_->opts .timeout = kShutdownTimeout ;
352
+ if (session_->stream .is_ssl ()) {
353
+ session_->stream .ssl ().next_layer ().cancel ();
354
+ }
344
355
session_->async_shutdown (beast::bind_front_handler (
345
- &FoxyClient::on_shutdown, std::move (completion)));
356
+ &FoxyClient::on_shutdown, shared_from_this (),
357
+ std::move (completion)));
346
358
}
347
359
348
- static void on_shutdown (std::function<void ()> completion,
349
- boost::system::error_code ec) {
350
- // Because do_shutdown doesn't use shared_from_this() when initiating
351
- // the async_shutdown op, the client may already be destroyed - hence
352
- // this static method.
360
+ void on_shutdown (std::function<void ()> completion,
361
+ boost::system::error_code ec) {
353
362
boost::ignore_unused (ec);
354
363
if (completion) {
355
364
completion ();
0 commit comments