From 70e11e82690b701dac8a25a9ca70153d2dec189c Mon Sep 17 00:00:00 2001 From: John Knox Date: Mon, 25 Jun 2018 15:56:35 -0700 Subject: [PATCH] Stop using folly Future::delayedUnsafe() Summary: delayedUnsafe() is unsafe because it disregards the executor you have specified, and uses the default one. Depending on the context, this can sometimes be an InlineExecutor, and since some of the scheduled jobs, schedule instances of themselves, this can cause infinite recursion to occur. Fixing this by using the safe variant of delayed, and also using a new instance of IOExecutor. We need a new Executor for the Sonar loop, because if we use the same worker thread as is provided to RSocket, we get deadlock when we wait for rsocket to connect. Reviewed By: danielbuechele Differential Revision: D8617679 fbshipit-source-id: 51ab3224b93e774596a8799338e7391e2eb956cb --- xplat/Sonar/SonarWebSocketImpl.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/xplat/Sonar/SonarWebSocketImpl.cpp b/xplat/Sonar/SonarWebSocketImpl.cpp index 343aa7956..eea0aeb90 100644 --- a/xplat/Sonar/SonarWebSocketImpl.cpp +++ b/xplat/Sonar/SonarWebSocketImpl.cpp @@ -8,6 +8,7 @@ #include "SonarWebSocketImpl.h" #include +#include #include #include #include @@ -92,15 +93,14 @@ class Responder : public rsocket::RSocketResponder { SonarWebSocketImpl::SonarWebSocketImpl(SonarInitConfig config) : deviceData_(config.deviceData), worker_(config.worker) {} +folly::IOExecutor* ioExecutor; + SonarWebSocketImpl::~SonarWebSocketImpl() { stop(); } void SonarWebSocketImpl::start() { - folly::makeFuture() - .via(worker_->getEventBase()) - .delayedUnsafe(std::chrono::milliseconds(0)) - .then([this]() { startSync(); }); + folly::makeFuture().via(ioExecutor).then([this]() { startSync(); }); } void SonarWebSocketImpl::startSync() { @@ -184,8 +184,8 @@ void SonarWebSocketImpl::connectSecurely() { void SonarWebSocketImpl::reconnect() { folly::makeFuture() - .via(worker_->getEventBase()) - .delayedUnsafe(std::chrono::seconds(reconnectIntervalSeconds)) + .via(ioExecutor) + .delayed(std::chrono::seconds(reconnectIntervalSeconds)) .then([this]() { startSync(); }); }