aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include/net/abstract_tcp_server2.inl
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-07-11 22:02:28 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-07-15 19:08:49 +0100
commit979105b2989746f1a426588862127d28c418f124 (patch)
tree14c771d1fc8b50948e8a525ed3f171a7860b12e4 /contrib/epee/include/net/abstract_tcp_server2.inl
parentMerge pull request #4094 (diff)
downloadmonero-979105b2989746f1a426588862127d28c418f124.tar.xz
abstract_tcp_server2: fix race on shutdown
Diffstat (limited to 'contrib/epee/include/net/abstract_tcp_server2.inl')
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.inl9
1 files changed, 8 insertions, 1 deletions
diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl
index 5b3550005..59a126163 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.inl
+++ b/contrib/epee/include/net/abstract_tcp_server2.inl
@@ -649,6 +649,10 @@ PRAGMA_WARNING_DISABLE_VS(4355)
template<class t_protocol_handler>
bool connection<t_protocol_handler>::shutdown()
{
+ CRITICAL_REGION_BEGIN(m_shutdown_lock);
+ if (m_was_shutdown)
+ return true;
+ m_was_shutdown = true;
// Initiate graceful connection closure.
m_timer.cancel();
boost::system::error_code ignored_ec;
@@ -658,7 +662,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
try { host_count(m_host, -1); } catch (...) { /* ignore */ }
m_host = "";
}
- m_was_shutdown = true;
+ CRITICAL_REGION_END();
m_protocol_handler.release_protocol();
return true;
}
@@ -667,6 +671,9 @@ PRAGMA_WARNING_DISABLE_VS(4355)
bool connection<t_protocol_handler>::close()
{
TRY_ENTRY();
+ auto self = safe_shared_from_this();
+ if(!self)
+ return false;
//_info("[sock " << socket_.native_handle() << "] Que Shutdown called.");
m_timer.cancel();
size_t send_que_size = 0;