Browse Source

bugfix: error code 995

cl-refactor
Vlad Gluhovsky 9 years ago
parent
commit
2996033df0
  1. 4
      libp2p/Common.h
  2. 24
      libp2p/NodeTable.cpp
  3. 3
      libp2p/NodeTable.h

4
libp2p/Common.h

@ -221,7 +221,7 @@ class DeadlineOps
{
public:
DeadlineOp(ba::io_service& _io, unsigned _msInFuture, std::function<void(boost::system::error_code const&)> const& _f): m_timer(new ba::deadline_timer(_io)) { m_timer->expires_from_now(boost::posix_time::milliseconds(_msInFuture)); m_timer->async_wait(_f); }
~DeadlineOp() {}
~DeadlineOp() { if (m_timer) m_timer->cancel(); }
DeadlineOp(DeadlineOp&& _s): m_timer(_s.m_timer.release()) {}
DeadlineOp& operator=(DeadlineOp&& _s) { m_timer.reset(_s.m_timer.release()); return *this; }
@ -241,6 +241,8 @@ public:
void schedule(unsigned _msInFuture, std::function<void(boost::system::error_code const&)> const& _f) { if (m_stopped) return; DEV_GUARDED(x_timers) m_timers.emplace_back(m_io, _msInFuture, _f); }
void stop() { m_stopped = true; DEV_GUARDED(x_timers) m_timers.clear(); }
bool isStopped() const { return m_stopped; }
protected:
void reap();

24
libp2p/NodeTable.cpp

@ -46,7 +46,6 @@ NodeTable::NodeTable(ba::io_service& _io, KeyPair const& _alias, NodeIPEndpoint
m_socket(new NodeSocket(_io, *this, (bi::udp::endpoint)m_node.endpoint)),
m_socketPointer(m_socket.get()),
m_timers(_io)
,m_debug_destroyed(false)
{
for (unsigned i = 0; i < s_bins; i++)
m_state[i].distance = i;
@ -68,12 +67,8 @@ NodeTable::NodeTable(ba::io_service& _io, KeyPair const& _alias, NodeIPEndpoint
NodeTable::~NodeTable()
{
DEV_GUARDED(x_debug)
{
m_debug_destroyed = true;
m_timers.stop();
m_socketPointer->disconnect();
}
m_socketPointer->disconnect();
m_timers.stop();
}
void NodeTable::processEvents()
@ -204,12 +199,17 @@ void NodeTable::doDiscover(NodeId _node, unsigned _round, shared_ptr<set<shared_
m_timers.schedule(c_reqTimeout.count() * 2, [this, _node, _round, _tried](boost::system::error_code const& _ec)
{
if (_ec)
clog(NodeTableWarn) << "Discovery timer canceled!";
clog(NodeTableWarn) << "Discovery timer canceled: " << _ec.value() << _ec.message();
if (995 == _ec.value() || m_timers.isStopped())
return;
// Error code 995 means that the timer was probably aborted. It usually happens when "this" object
// is deallocated, in which case subsequent call to doDiscover() would cause a crash.
// We can not rely on m_timers.isStopped(), because "this" pointer was captured by the lambda,
// and therefore, in case of deallocation m_timers object no longer exists.
if (!m_debug_destroyed)
DEV_GUARDED(x_debug)
if (!m_debug_destroyed)
doDiscover(_node, _round + 1, _tried);
doDiscover(_node, _round + 1, _tried);
});
}

3
libp2p/NodeTable.h

@ -265,9 +265,6 @@ private:
NodeSocket* m_socketPointer; ///< Set to m_socket.get(). Socket is created in constructor and disconnected in destructor to ensure access to pointer is safe.
DeadlineOps m_timers;
Mutex x_debug;
bool m_debug_destroyed;
};
inline std::ostream& operator<<(std::ostream& _out, NodeTable const& _nodeTable)

Loading…
Cancel
Save