From 4f9c2c031084f06398211185ea3d34cbaa4149a2 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Tue, 10 Jan 2017 08:24:06 -0500 Subject: [PATCH] roots: don't deadlock while deleting a crawl thread BeesRoots::crawl_state_erase may invoke BeesCrawl::~BeesCrawl, which will do a join on its crawl thread, which might be trying to lock BeesRoots::m_mutex, which is locked by crawl_state_erase at the time. Fix this by creating an extra reference to the BeesCrawl object, then releasing the lock on BeesRoots::m_mutex, then deleting the reference. The BeesCrawl object may still call methods on BeesRoots, but the only such method is BeesRoots::crawl_state_set_dirty, and that method has no dependency on the erased BeesCrawl shared_ptr. Signed-off-by: Zygo Blaxell --- src/bees-roots.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bees-roots.cc b/src/bees-roots.cc index e1c1f4e..5760492 100644 --- a/src/bees-roots.cc +++ b/src/bees-roots.cc @@ -154,8 +154,10 @@ BeesRoots::crawl_state_erase(const BeesCrawlState &bcs) auto found = m_root_crawl_map.find(bcs.m_root); if (found != m_root_crawl_map.end()) { + auto hold_this_until_unlocked = found->second; m_root_crawl_map.erase(found); m_crawl_dirty = true; + lock.unlock(); } }