From dfcfa9f7fada34f45def6dfd1223daa026e6efd0 Mon Sep 17 00:00:00 2001 From: John Knox Date: Wed, 15 Aug 2018 06:03:07 -0700 Subject: [PATCH] Handle socket not open error individually Summary: It's expected that whenever not connected to a desktop, or when the sonar desktop app isn't running, we'll get errors connecting. Isolate these so we can treat all other exceptions properly. Reviewed By: passy Differential Revision: D9333323 fbshipit-source-id: c9853ca84d1a04827ebf7bae0fe87859ca6110d1 --- xplat/Sonar/SonarWebSocketImpl.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/xplat/Sonar/SonarWebSocketImpl.cpp b/xplat/Sonar/SonarWebSocketImpl.cpp index 0b0dde106..8ee31fb5a 100644 --- a/xplat/Sonar/SonarWebSocketImpl.cpp +++ b/xplat/Sonar/SonarWebSocketImpl.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "CertificateUtils.h" #ifdef __ANDROID__ @@ -116,14 +117,25 @@ void SonarWebSocketImpl::startSync() { SONAR_LOG("Already connected"); return; } + auto connect = sonarState_->start("Connect to desktop"); try { if (isCertificateExchangeNeeded()) { doCertificateExchange(); return; } - connectSecurely(); - } catch (const std::exception&) { + + connect->complete(); + } catch (const folly::AsyncSocketException& e) { + if (e.getType() == folly::AsyncSocketException::NOT_OPEN) { + // The expected code path when flipper desktop is not running. + } else { + SONAR_LOG(e.what()); + failedConnectionAttempts_++; + } + reconnect(); + } catch (const std::exception& e) { + SONAR_LOG(e.what()); failedConnectionAttempts_++; reconnect(); }