[netemul] Fix race in Sandbox destructor
- Sandbox was using a default destructor, which could cause race with
the FIDL bindings error callbacks kept in Sandbox::procs_.
BUG: FLK-178 #done
Change-Id: I46189bde74fa4d83faec27f503f9ec032c605906
diff --git a/src/connectivity/network/testing/netemul/runner/sandbox.cc b/src/connectivity/network/testing/netemul/runner/sandbox.cc
index f4b8ee8..ce7fd45 100644
--- a/src/connectivity/network/testing/netemul/runner/sandbox.cc
+++ b/src/connectivity/network/testing/netemul/runner/sandbox.cc
@@ -56,6 +56,19 @@
});
}
+Sandbox::~Sandbox() {
+ ASSERT_MAIN_DISPATCHER;
+ if (helper_loop_) {
+ helper_loop_->Quit();
+ helper_loop_->JoinThreads();
+ // Remove all pending process handlers before shutting
+ // down the loop to prevent error callbacks from
+ // being fired.
+ procs_.clear();
+ helper_loop_ = nullptr;
+ }
+}
+
void Sandbox::Start(async_dispatcher_t* dispatcher) {
main_dispatcher_ = dispatcher;
setup_done_ = false;
diff --git a/src/connectivity/network/testing/netemul/runner/sandbox.h b/src/connectivity/network/testing/netemul/runner/sandbox.h
index b539177..9504f72 100644
--- a/src/connectivity/network/testing/netemul/runner/sandbox.h
+++ b/src/connectivity/network/testing/netemul/runner/sandbox.h
@@ -38,6 +38,7 @@
using RootEnvironmentCreatedCallback =
fit::function<void(ManagedEnvironment*)>;
explicit Sandbox(SandboxArgs args);
+ ~Sandbox();
void SetTerminationCallback(TerminationCallback callback) {
termination_callback_ = std::move(callback);
diff --git a/src/connectivity/network/testing/netemul/runner/sandbox_unittest.cc b/src/connectivity/network/testing/netemul/runner/sandbox_unittest.cc
index a40cb28..2e5c752 100644
--- a/src/connectivity/network/testing/netemul/runner/sandbox_unittest.cc
+++ b/src/connectivity/network/testing/netemul/runner/sandbox_unittest.cc
@@ -745,7 +745,7 @@
RunSandboxInternalError();
}
-TEST_F(SandboxTest, DISABLED_DestructorRunsCleanly) {
+TEST_F(SandboxTest, DestructorRunsCleanly) {
// This test verifies that if the sandbox is destroyed while tests are
// running inside it, it'll shutdown cleanly.
// Specifically, this test was added due to a crash in the destruction