Fix EAGAIN bug in ZMQ-RPC/ZMQ-PUB

This commit is contained in:
Lee *!* Clagett 2023-11-04 13:39:37 -04:00
parent d9b765a3af
commit fe746dca4e

View file

@ -158,9 +158,17 @@ void ZmqServer::serve()
if (!pub || sockets[2].revents) if (!pub || sockets[2].revents)
{ {
std::string message = MONERO_UNWRAP(net::zmq::receive(rep.get(), read_flags)); expect<std::string> message = net::zmq::receive(rep.get(), read_flags);
MDEBUG("Received RPC request: \"" << message << "\""); if (!message)
epee::byte_slice response = handler.handle(std::move(message)); {
// EAGAIN can occur when using `zmq_poll`, which doesn't inspect for message validity
if (message != net::zmq::make_error_code(EAGAIN))
MONERO_THROW(message.error(), "Read failure on ZMQ-RPC");
}
else // no errors
{
MDEBUG("Received RPC request: \"" << *message << "\"");
epee::byte_slice response = handler.handle(std::move(*message));
const boost::string_ref response_view{reinterpret_cast<const char*>(response.data()), response.size()}; const boost::string_ref response_view{reinterpret_cast<const char*>(response.data()), response.size()};
MDEBUG("Sending RPC reply: \"" << response_view << "\""); MDEBUG("Sending RPC reply: \"" << response_view << "\"");
@ -168,6 +176,7 @@ void ZmqServer::serve()
} }
} }
} }
}
catch (const std::system_error& e) catch (const std::system_error& e)
{ {
if (e.code() != net::zmq::make_error_code(ETERM)) if (e.code() != net::zmq::make_error_code(ETERM))