mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-20 01:40:29 +00:00
Stop WSConnection from calling ::exit(), so that the sync command can flush its writes first
This fixes a rare race condition that caused a segfault on exit: We call ::exit() which runs the atexit handler, which destroys the LMDB environment. However, there was another thread running that still had pending events to write, so as the environment was being destroyed, it tried to use the environment to write the events.
This commit is contained in:
@ -23,6 +23,8 @@ class WSConnection {
|
||||
std::function<void()> onConnect;
|
||||
std::function<void(std::string_view, uWS::OpCode, size_t)> onMessage;
|
||||
std::function<void()> onTrigger;
|
||||
std::function<void()> onDisconnect;
|
||||
std::function<void()> onError;
|
||||
bool reconnect = true;
|
||||
uint64_t reconnectDelayMilliseconds = 5'000;
|
||||
std::string remoteAddr;
|
||||
@ -84,8 +86,8 @@ class WSConnection {
|
||||
if (ws == currWs) {
|
||||
currWs = nullptr;
|
||||
|
||||
if (!reconnect) ::exit(1);
|
||||
doConnect(reconnectDelayMilliseconds);
|
||||
if (onDisconnect) onDisconnect();
|
||||
if (reconnect) doConnect(reconnectDelayMilliseconds);
|
||||
} else {
|
||||
LI << "Got disconnect for unexpected connection?";
|
||||
}
|
||||
@ -94,8 +96,8 @@ class WSConnection {
|
||||
hubGroup->onError([&](void *) {
|
||||
LI << "Websocket connection error";
|
||||
|
||||
if (!reconnect) ::exit(1);
|
||||
doConnect(reconnectDelayMilliseconds);
|
||||
if (onError) onError();
|
||||
if (reconnect) doConnect(reconnectDelayMilliseconds);
|
||||
});
|
||||
|
||||
hubGroup->onMessage2([&](uWS::WebSocket<uWS::CLIENT> *ws, char *message, size_t length, uWS::OpCode opCode, size_t compressedSize) {
|
||||
|
Reference in New Issue
Block a user