Skip initialisation if not running in own thread
Summary: One design goal of sonar is to never cause the host app to crash or hang. For this reason, we do all heavy work in a background thread. If we detect that it's not running in it's own thread, just return so we don't hold up the caller. Reviewed By: danielbuechele Differential Revision: D8767288 fbshipit-source-id: e146cc2cfe5c3e62d12f527ff79f24c74873d4ff
This commit is contained in:
committed by
Facebook Github Bot
parent
85e6bf6d51
commit
d0ecb46d64
@@ -33,6 +33,8 @@
|
|||||||
#define SONAR_CA_FILE_NAME "sonarCA.crt"
|
#define SONAR_CA_FILE_NAME "sonarCA.crt"
|
||||||
#define CLIENT_CERT_FILE_NAME "device.crt"
|
#define CLIENT_CERT_FILE_NAME "device.crt"
|
||||||
#define PRIVATE_KEY_FILE "privateKey.pem"
|
#define PRIVATE_KEY_FILE "privateKey.pem"
|
||||||
|
#define WRONG_THREAD_EXIT_MSG \
|
||||||
|
"ERROR: Aborting sonar initialization because it's not running in the sonar thread."
|
||||||
|
|
||||||
static constexpr int reconnectIntervalSeconds = 2;
|
static constexpr int reconnectIntervalSeconds = 2;
|
||||||
static constexpr int connectionKeepaliveSeconds = 10;
|
static constexpr int connectionKeepaliveSeconds = 10;
|
||||||
@@ -104,6 +106,10 @@ void SonarWebSocketImpl::start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SonarWebSocketImpl::startSync() {
|
void SonarWebSocketImpl::startSync() {
|
||||||
|
if (!isRunningInOwnThread()) {
|
||||||
|
SONAR_LOG(WRONG_THREAD_EXIT_MSG);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (isOpen()) {
|
if (isOpen()) {
|
||||||
SONAR_LOG("Already connected");
|
SONAR_LOG("Already connected");
|
||||||
return;
|
return;
|
||||||
@@ -289,6 +295,10 @@ bool SonarWebSocketImpl::ensureSonarDirExists() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SonarWebSocketImpl::isRunningInOwnThread() {
|
||||||
|
return sonarEventBase_->isInEventBaseThread();
|
||||||
|
}
|
||||||
|
|
||||||
bool fileExists(std::string fileName) {
|
bool fileExists(std::string fileName) {
|
||||||
struct stat buffer;
|
struct stat buffer;
|
||||||
return stat(fileName.c_str(), &buffer) == 0;
|
return stat(fileName.c_str(), &buffer) == 0;
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ class SonarWebSocketImpl : public SonarWebSocket {
|
|||||||
bool isCertificateExchangeNeeded();
|
bool isCertificateExchangeNeeded();
|
||||||
void requestSignedCertFromSonar();
|
void requestSignedCertFromSonar();
|
||||||
bool ensureSonarDirExists();
|
bool ensureSonarDirExists();
|
||||||
|
bool isRunningInOwnThread();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sonar
|
} // namespace sonar
|
||||||
|
|||||||
Reference in New Issue
Block a user