From 0930e8c4575685ec604bd51b7aaec664862f64c9 Mon Sep 17 00:00:00 2001 From: Marin Tomic Date: Fri, 3 Nov 2017 13:55:26 +0100 Subject: [PATCH] Fix name uniqueness check in System.Spawn Summary: Old code would start reactor thread first, and then try to insert it in unordered_map. If it failed to insert it, the thread handler would get destructed with thread still running, which raises an exception. Reviewers: buda, mislav.bradac Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D956 --- src/communication/reactor/reactor_local.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/communication/reactor/reactor_local.hpp b/src/communication/reactor/reactor_local.hpp index 36138c4b9..e7ad3040d 100644 --- a/src/communication/reactor/reactor_local.hpp +++ b/src/communication/reactor/reactor_local.hpp @@ -525,15 +525,15 @@ class System : public ChannelFinder { finder = this; } std::unique_lock lock(mutex_); + CHECK(reactors_.find(name) == reactors_.end()) + << "Reactor with name: '" << name << "' already exists."; std::unique_ptr reactor(new Reactor(*finder, name, setup)); std::thread reactor_thread([reactor = reactor.get()] { reactor->setup_(*reactor); reactor->RunEventLoop(); }); - auto got = reactors_.emplace( - name, std::pair{ - std::move(reactor), std::move(reactor_thread)}); - CHECK(got.second) << "Reactor with name: '" << name << "' already exists"; + reactors_.emplace(name, std::pair{ + std::move(reactor), std::move(reactor_thread)}); } std::shared_ptr FindChannel(