From 35a9d1f612df919542fdd6d72a29875413f8496b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Thu, 18 Apr 2019 17:37:27 -0400 Subject: [PATCH] proxy client: catch exception in Http::close() --- src/dht_proxy_client.cpp | 58 +++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/src/dht_proxy_client.cpp b/src/dht_proxy_client.cpp index 1c8f0b37..6bd6297a 100644 --- a/src/dht_proxy_client.cpp +++ b/src/dht_proxy_client.cpp @@ -135,7 +135,14 @@ DhtProxyClient::cancelAllOperations() while (operation != operations_.end()) { if (operation->thread.joinable()) { // Close connection to stop operation? - restbed::Http::close(operation->req); + if (operation->req) { + try { + restbed::Http::close(operation->req); + } catch (const std::exception& e) { + DHT_LOG.w("Error closing socket: %s", e.what()); + } + operation->req.reset(); + } operation->thread.join(); operation = operations_.erase(operation); } else { @@ -157,8 +164,14 @@ DhtProxyClient::cancelAllListeners() if (l->second.thread.joinable()) { // Close connection to stop listener? l->second.state->cancel = true; - if (l->second.req) - restbed::Http::close(l->second.req); + if (l->second.req) { + try { + restbed::Http::close(l->second.req); + } catch (const std::exception& e) { + DHT_LOG.w("Error closing socket: %s", e.what()); + } + l->second.req.reset(); + } l->second.thread.join(); } s.second.listeners.erase(token); @@ -224,7 +237,14 @@ DhtProxyClient::periodic(const uint8_t*, size_t, const SockAddr&) if (*(operation->finished)) { if (operation->thread.joinable()) { // Close connection to stop operation? - restbed::Http::close(operation->req); + if (operation->req) { + try { + restbed::Http::close(operation->req); + } catch (const std::exception& e) { + DHT_LOG.w("Error closing socket: %s", e.what()); + } + operation->req.reset(); + } operation->thread.join(); } operation = operations_.erase(operation); @@ -875,8 +895,14 @@ DhtProxyClient::doCancelListen(const InfoHash& key, size_t ltoken) // Just stop the request if (listener.thread.joinable()) { // Close connection to stop listener - if (listener.req) - restbed::Http::close(listener.req); + if (listener.req) { + try { + restbed::Http::close(listener.req); + } catch (const std::exception& e) { + DHT_LOG.w("Error closing socket: %s", e.what()); + } + listener.req.reset(); + } listener.thread.join(); } } @@ -942,8 +968,14 @@ DhtProxyClient::restartListeners() auto state = listener.state; if (listener.thread.joinable()) { state->cancel = true; - if (listener.req) - restbed::Http::close(listener.req); + if (listener.req) { + try { + restbed::Http::close(listener.req); + } catch (const std::exception& e) { + DHT_LOG.w("Error closing socket: %s", e.what()); + } + listener.req.reset(); + } listener.thread.join(); } // Redo listen @@ -1053,8 +1085,14 @@ DhtProxyClient::resubscribe(const InfoHash& key, Listener& listener) auto state = listener.state; if (listener.thread.joinable()) { state->cancel = true; - if (listener.req) - restbed::Http::close(listener.req); + if (listener.req) { + try { + restbed::Http::close(listener.req); + } catch (const std::exception& e) { + DHT_LOG.w("Error closing socket: %s", e.what()); + } + listener.req.reset(); + } listener.thread.join(); } state->cancel = false; -- GitLab