Skip to content

Commit

Permalink
Merge pull request #384 from skalenetwork/bug/SKALE-5014-crash-on-bad…
Browse files Browse the repository at this point in the history
…-socket-type

SKALE-5014 change exit to exception on bad socket
  • Loading branch information
olehnikolaiev authored Feb 28, 2022
2 parents 188bf20 + 683be22 commit 21e5b8a
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions zmq_src/ZMQServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,25 +211,27 @@ pair <string, shared_ptr<zmq::message_t>> ZMQServer::receiveMessage() {

if (!socket->recv(identity.get())) {
checkForExit();
// something terrible happened
spdlog::error("Fatal error: socket->recv(&identity) returned false. Exiting.");
exit(-11);
// bad socket type
spdlog::error("Error: socket->recv(&identity) returned false.");
throw SGXException(ZMQ_SERVER_ERROR, "Error: socket->recv(&identity) returned false.");
}

if (!identity->more()) {
checkForExit();
// something terrible happened
spdlog::error("Fatal error: zmq_msg_more(identity) returned false. Exiting.");
exit(-12);
// bad socket type
spdlog::error("Error: zmq_msg_more(identity) returned false.");
throw SGXException(ZMQ_SERVER_ERROR, "Error: zmq_msg_more(identity) returned false.");
}
auto id = string((char *) identity->data(), identity->size());
spdlog::debug("Received identity via ZMQ server: {}", id);

auto reqMsg = make_shared<zmq::message_t>();

if (!socket->recv(reqMsg.get(), 0)) {
checkForExit();
// something terrible happened
spdlog::error("Fatal error: socket.recv(&reqMsg, 0) returned false. Exiting");
exit(-13);
// bad socket type
spdlog::error("Error: socket.recv(&reqMsg, 0) returned false.");
throw SGXException(ZMQ_SERVER_ERROR, "Error: socket.recv(&reqMsg, 0) returned false.");
}

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

0 comments on commit 21e5b8a

Please sign in to comment.