Skip to content

Commit dc087b9

Browse files
committed
use simplest solution
1 parent a1473e6 commit dc087b9

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

examples/hello-cpp-client/main.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,6 @@ int main() {
6262
std::cout << "*** Feature flag '" << FEATURE_FLAG_KEY << "' is "
6363
<< (flag_value ? "true" : "false") << " for this user\n\n";
6464

65-
for (int i = 0; i < 5; i++) {
66-
auto user_key = "example-user-key-" + std::to_string(i);
67-
auto context2 =
68-
ContextBuilder().Kind("user", user_key).Name("Bob").Build();
69-
70-
std::cout << "identifying " << user_key << std::endl;
71-
auto fut = client.IdentifyAsync(context2);
72-
fut.wait();
73-
std::cout << "identified " << user_key << "!" << std::endl;
74-
75-
std::this_thread::sleep_for(std::chrono::seconds(5));
76-
}
77-
7865
return 0;
7966
}
8067

libs/server-sent-events/src/client.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,28 @@ class FoxyClient : public Client,
340340
shutting_down_ = true;
341341
// If any backoff is taking place, cancel that as well.
342342
backoff_timer_.cancel();
343-
344-
boost::system::error_code ec = {};
343+
344+
// Cancels the outstanding read.
345+
if (session_->stream.is_ssl()) {
346+
session_->stream.ssl().next_layer().cancel();
347+
} else {
348+
session_->stream.plain().cancel();
349+
}
350+
351+
// Ideally we would call session_->async_shutdown() here to gracefully
352+
// terminate the SSL session. For unknown reasons, this call appears to
353+
// hang indefinitely and never complete until the SDK client is
354+
// destroyed.
355+
//
356+
// A workaround is to set a timeout on the operation, say 1 second. This
357+
// gives the opportunity to shutdown gracefully and then if that fails,
358+
// we could close the socket directly. But that also doesn't seem to
359+
// work: even with the timeout, the operation still doesn't complete.
360+
//
361+
// So the most robust solution appears to be closing the socket
362+
// directly. This is not ideal because it doesn't send a close_notify to
363+
// the server.
364+
boost::system::error_code ec;
345365
session_->stream.plain().shutdown(
346366
boost::asio::ip::tcp::socket::shutdown_both, ec);
347367
session_->stream.plain().close(ec);

0 commit comments

Comments
 (0)