From 8e1b2dffa5634d1d007a6128f7c9478f4be0b021 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Sun, 29 Mar 2020 14:40:21 -0300 Subject: [PATCH] Catch connect failures socket.connect() can throw, e.g. if given an invalid connection address; catch this, log the error, and return a failure condition. --- lokimq/connections.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lokimq/connections.cpp b/lokimq/connections.cpp index 3af95bd..b3f829f 100644 --- a/lokimq/connections.cpp +++ b/lokimq/connections.cpp @@ -104,7 +104,14 @@ LokiMQ::proxy_connect_sn(string_view remote, string_view connect_hint, bool opti LMQ_LOG(debug, to_hex(pubkey), " (me) connecting to ", addr, " to reach ", to_hex(remote)); zmq::socket_t socket{context, zmq::socket_type::dealer}; setup_outgoing_socket(socket, remote); - socket.connect(addr); + try { + socket.connect(addr); + } catch (const zmq::error_t& e) { + // Note that this failure cases indicates something serious went wrong that means zmq isn't + // even going to try connecting (for example an unparseable remote address). + LMQ_LOG(error, "Outgoing connection to ", addr, " failed: ", e.what()); + return {nullptr, ""s}; + } peer_info p{}; p.service_node = true; p.pubkey = std::string{remote};