Skip to content

Commit ae0013c

Browse files
authored
fix: Handle exception closing stream for unavailable adapter on windows. (#427)
On windows shutting down a stream for an adapter that is no longer available would crash. I was testing this by disabling adapters, but my suspicion is after a computer sleeps it may take some time for the adapters to recover on windows.
1 parent 8b6913d commit ae0013c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,21 @@ class FoxyClient : public Client,
341341
// If any backoff is taking place, cancel that as well.
342342
backoff_timer_.cancel();
343343

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();
344+
try {
345+
// Cancels the outstanding read.
346+
if (session_->stream.is_ssl()) {
347+
session_->stream.ssl().next_layer().cancel();
348+
} else {
349+
session_->stream.plain().cancel();
350+
}
351+
} catch (boost::system::system_error const& err) {
352+
// The stream is likely already closed. Potentially the network
353+
// interface that was associated with the stream is no longer
354+
// available.
355+
logger_("exception closing stream: " + std::string(err.what()));
349356
}
350357

358+
351359
// Ideally we would call session_->async_shutdown() here to gracefully
352360
// terminate the SSL session. For unknown reasons, this call appears to
353361
// hang indefinitely and never complete until the SDK client is

0 commit comments

Comments
 (0)