@@ -58,7 +58,6 @@ class FoxyClient : public Client,
58
58
using cb = std::function<void (launchdarkly::sse::Event)>;
59
59
using body = launchdarkly::sse::detail::EventBody<cb>;
60
60
using response = http::response<body>;
61
- int count;
62
61
63
62
public:
64
63
FoxyClient (boost::asio::any_io_executor executor,
@@ -91,8 +90,7 @@ class FoxyClient : public Client,
91
90
kDefaultMaxBackoffDelay),
92
91
backoff_timer_(std::move(executor)),
93
92
last_read_(std::nullopt),
94
- shutting_down_(false ),
95
- count(get_counter()) {
93
+ shutting_down_(false ) {
96
94
create_session ();
97
95
create_parser ();
98
96
}
@@ -282,17 +280,10 @@ class FoxyClient : public Client,
282
280
void on_read_body (boost::system::error_code ec, std::size_t amount) {
283
281
boost::ignore_unused (amount);
284
282
if (ec) {
283
+ if (shutting_down_) {
284
+ return ;
285
+ }
285
286
if (ec == boost::asio::error::operation_aborted) {
286
- // operation_aborted can occur if the read timeout is reached or
287
- // if we're shutting down, so shutting_down_ is needed to
288
- // disambiguate.
289
- if (shutting_down_) {
290
- boost::system::error_code ec = {};
291
- session_->stream .plain ().shutdown (
292
- boost::asio::ip::tcp::socket::shutdown_both, ec);
293
- session_->stream .plain ().close (ec);
294
- return ;
295
- }
296
287
errors_ (Error::ReadTimeout);
297
288
return async_backoff (
298
289
" aborting read of response body (timeout)" );
@@ -344,18 +335,17 @@ class FoxyClient : public Client,
344
335
}
345
336
346
337
void do_shutdown (std::function<void ()> completion) {
338
+ // Signal to the body reader operation that if it completes,
339
+ // it should return instead of starting another async read.
347
340
shutting_down_ = true ;
341
+ // If any backoff is taking place, cancel that as well.
348
342
backoff_timer_.cancel ();
349
- if (session_->stream .is_ssl ()) {
350
- session_->stream .ssl ().next_layer ().cancel ();
351
- } else {
352
- session_->stream .plain ().cancel ();
353
- }
354
- }
343
+
344
+ boost::system::error_code ec = {};
345
+ session_->stream .plain ().shutdown (
346
+ boost::asio::ip::tcp::socket::shutdown_both, ec);
347
+ session_->stream .plain ().close (ec);
355
348
356
- void on_shutdown (std::function<void ()> completion,
357
- boost::system::error_code ec) {
358
- boost::ignore_unused (ec);
359
349
if (completion) {
360
350
completion ();
361
351
}
0 commit comments