From eb1981f9f23f1951949ba43724c4dd65b2e2ba9c Mon Sep 17 00:00:00 2001 From: John Knox Date: Fri, 24 Apr 2020 05:50:04 -0700 Subject: [PATCH] Don't log when insecure connection fails Summary: Context: https://fb.workplace.com/groups/flippersupport/permalink/803808233433170/ A similar change was done earlier with the secure connection route. This does the same for the insecure route. Reviewed By: mweststrate Differential Revision: D21227196 fbshipit-source-id: 844cb674b5b16033977f451bbc3d8bbc69732273 --- .../Flipper/FlipperConnectionManagerImpl.cpp | 26 ++++++++++++++++--- xplat/Flipper/FlipperConnectionManagerImpl.h | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/xplat/Flipper/FlipperConnectionManagerImpl.cpp b/xplat/Flipper/FlipperConnectionManagerImpl.cpp index de5748aa7..288e9825a 100644 --- a/xplat/Flipper/FlipperConnectionManagerImpl.cpp +++ b/xplat/Flipper/FlipperConnectionManagerImpl.cpp @@ -127,7 +127,11 @@ void FlipperConnectionManagerImpl::startSync() { : "Establish main connection"); try { if (isClientSetupStep) { - doCertificateExchange(); + bool success = doCertificateExchange(); + if (!success) { + reconnect(); + return; + } } else { if (!connectSecurely()) { // The expected code path when flipper desktop is not running. @@ -162,7 +166,7 @@ void FlipperConnectionManagerImpl::startSync() { } } -void FlipperConnectionManagerImpl::doCertificateExchange() { +bool FlipperConnectionManagerImpl::doCertificateExchange() { rsocket::SetupParameters parameters; folly::SocketAddress address; @@ -173,7 +177,7 @@ void FlipperConnectionManagerImpl::doCertificateExchange() { auto connectingInsecurely = flipperState_->start("Connect insecurely"); connectionIsTrusted_ = false; - client_ = + auto newClient = rsocket::RSocket::createConnectedClient( std::make_unique( *connectionEventBase_->getEventBase(), std::move(address)), @@ -182,7 +186,22 @@ void FlipperConnectionManagerImpl::doCertificateExchange() { std::chrono::seconds(connectionKeepaliveSeconds), // keepaliveInterval nullptr, // stats std::make_shared(this)) + .thenError([](const auto& e) { + if (e.getType() == folly::AsyncSocketException::NOT_OPEN || + e.getType() == folly::AsyncSocketException::NETWORK_ERROR) { + // This is the state where no Flipper desktop client is connected. + // We don't want an exception thrown here. + return std::unique_ptr(nullptr); + } + throw e; + }) .get(); + + if (newClient.get() == nullptr) { + return false; + } + + client_ = std::move(newClient); connectingInsecurely->complete(); auto resettingState = flipperState_->start("Reset state"); @@ -190,6 +209,7 @@ void FlipperConnectionManagerImpl::doCertificateExchange() { resettingState->complete(); requestSignedCertFromFlipper(); + return true; } bool FlipperConnectionManagerImpl::connectSecurely() { diff --git a/xplat/Flipper/FlipperConnectionManagerImpl.h b/xplat/Flipper/FlipperConnectionManagerImpl.h index 890430ac7..004c5be31 100644 --- a/xplat/Flipper/FlipperConnectionManagerImpl.h +++ b/xplat/Flipper/FlipperConnectionManagerImpl.h @@ -68,7 +68,7 @@ class FlipperConnectionManagerImpl : public FlipperConnectionManager { std::shared_ptr contextStore_; void startSync(); - void doCertificateExchange(); + bool doCertificateExchange(); bool connectSecurely(); bool isCertificateExchangeNeeded(); void requestSignedCertFromFlipper();