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.
This commit is contained in:
moneromooo-monero 2019-12-30 17:24:42 +00:00
parent 6c7d928f19
commit 21fe6a289b
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
2 changed files with 12 additions and 5 deletions

View file

@ -949,7 +949,12 @@ bool async_protocol_handler_config<t_connection_context>::close(boost::uuids::uu
{
CRITICAL_REGION_LOCAL(m_connects_lock);
async_protocol_handler<t_connection_context>* 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<class t_connection_context>