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
This commit is contained in:
committed by
Facebook Github Bot
parent
361a4cca76
commit
70e11e8269
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "SonarWebSocketImpl.h"
|
||||
#include <folly/String.h>
|
||||
#include <folly/executors/IOExecutor.h>
|
||||
#include <folly/futures/Future.h>
|
||||
#include <folly/io/async/SSLContext.h>
|
||||
#include <folly/json.h>
|
||||
@@ -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(); });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user