From 21fe6a289b934bd96bf83d5d23ece14ec850df27 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Mon, 30 Dec 2019 17:24:42 +0000 Subject: p2p: fix frequent weak_ptr exception on connection When a handshake fails, it can fail due to timeout or destroyed connection, in which case the connection will be, or already is, closed, and we don't want to do it twice. Additionally, when closing a connection directly from the top level code, ensure the connection is gone from the m_connects list so it won't be used again. AFAICT this is now clean in netstat, /proc/PID/fd and print_cn. This fixes a noisy (but harmless) exception. --- contrib/epee/include/net/levin_protocol_handler_async.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'contrib') diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h index 5774c0ba7..1341a4ae6 100644 --- a/contrib/epee/include/net/levin_protocol_handler_async.h +++ b/contrib/epee/include/net/levin_protocol_handler_async.h @@ -949,7 +949,12 @@ bool async_protocol_handler_config::close(boost::uuids::uu { CRITICAL_REGION_LOCAL(m_connects_lock); async_protocol_handler* aph = find_connection(connection_id); - return 0 != aph ? aph->close() : false; + if (!aph) + return false; + if (!aph->close()) + return false; + m_connects.erase(connection_id); + return true; } //------------------------------------------------------------------------------------------ template -- cgit v1.2.3