Skip to content

Commit

Permalink
Merge pull request #374 from skalenetwork/bug/SKALE-4939-fix-invalid-…
Browse files Browse the repository at this point in the history
…zmq-message-proccessing

SKALE-4939 fix invalid zmq message proccessing
  • Loading branch information
kladkogex authored Feb 1, 2022
2 parents ec057a9 + c98c161 commit d6f8b78
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions zmq_src/ZMQServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ pair <string, shared_ptr<zmq::message_t>> ZMQServer::receiveMessage() {
if (!identity->more()) {
checkForExit();
// something terrible happened
spdlog::error("Fatal error: zmq_msg_more(identity) returned false. Existing.");
spdlog::error("Fatal error: zmq_msg_more(identity) returned false. Exiting.");
exit(-12);
}

Expand All @@ -234,8 +234,6 @@ pair <string, shared_ptr<zmq::message_t>> ZMQServer::receiveMessage() {

auto result = string((char *) reqMsg->data(), reqMsg->size());

CHECK_STATE(result.front() == '{')
CHECK_STATE(result.back() == '}')
return {result, identity};
}

Expand All @@ -257,7 +255,7 @@ void ZMQServer::sendToClient(Json::Value &_result, shared_ptr <zmq::message_t> &
if (!s_send(*socket, replyStr)) {
exit(-16);
}
} catch (ExitRequestedException) {
} catch (ExitRequestedException&) {
throw;
} catch (exception &e) {
checkForExit();
Expand All @@ -276,7 +274,7 @@ void ZMQServer::doOneServerLoop() {
Json::Value result;
result["status"] = ZMQ_SERVER_ERROR;

shared_ptr <zmq::message_t> identity = nullptr;
shared_ptr <zmq::message_t> identity = make_shared<zmq::message_t>();
string msgStr;

try {
Expand Down Expand Up @@ -313,7 +311,7 @@ void ZMQServer::doOneServerLoop() {
incomingQueue.at(index).enqueue(element);
}

} catch (ExitRequestedException) {
} catch (ExitRequestedException&) {
throw;
} catch (exception &e) {
checkForExit();
Expand Down Expand Up @@ -348,7 +346,7 @@ void ZMQServer::workerThreadProcessNextMessage(uint64_t _threadNumber) {
.wait_dequeue_timed(element, std::chrono::milliseconds(1000))) {
checkForExit();
}
} catch (ExitRequestedException) {
} catch (ExitRequestedException&) {
throw;
} catch (exception &e) {
checkForExit();
Expand All @@ -364,7 +362,7 @@ void ZMQServer::workerThreadProcessNextMessage(uint64_t _threadNumber) {

try {
result = element.first->process();
} catch (ExitRequestedException) {
} catch (ExitRequestedException&) {
throw;
} catch (exception &e) {
checkForExit();
Expand Down Expand Up @@ -400,4 +398,4 @@ void ZMQServer::workerThreadMessageProcessLoop(ZMQServer *_agent, uint64_t _thre
}

spdlog::info("Exit requested. Exiting worker thread:" + to_string(_threadNumber));
}
}

0 comments on commit d6f8b78

Please sign in to comment.