From 107bf169a8527849d96ce81dc019b5ca71eb289a Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Mon, 4 Jun 2012 15:14:41 -0700 Subject: [PATCH] Bug 760007, part 2: Fix shutdown race condition in cross-process TestOpens. r=bent --- ipc/ipdl/test/cxx/TestOpens.cpp | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/ipc/ipdl/test/cxx/TestOpens.cpp b/ipc/ipdl/test/cxx/TestOpens.cpp index 4b17b42c7683..a8d2ec97e4cf 100644 --- a/ipc/ipdl/test/cxx/TestOpens.cpp +++ b/ipc/ipdl/test/cxx/TestOpens.cpp @@ -238,6 +238,24 @@ TestOpensOpenedChild::AnswerHiRpc() return true; } +static void +ShutdownTestOpensOpenedChild(TestOpensOpenedChild* child, + Transport* transport) +{ + delete child; + + // Now delete the transport, which has to happen after the + // top-level actor is deleted. + XRE_GetIOMessageLoop()->PostTask( + FROM_HERE, + new DeleteTask(transport)); + + // Kick off main-thread shutdown. + gMainThread->PostTask( + FROM_HERE, + NewRunnableMethod(gOpensChild, &TestOpensChild::Close)); +} + void TestOpensOpenedChild::ActorDestroy(ActorDestroyReason why) { @@ -248,18 +266,12 @@ TestOpensOpenedChild::ActorDestroy(ActorDestroyReason why) // ActorDestroy() is just a callback from IPDL-generated code, // which needs the top-level actor (this) to stay alive a little - // longer so other things can be cleaned up. + // longer so other things can be cleaned up. Defer shutdown to + // let cleanup finish. MessageLoop::current()->PostTask( FROM_HERE, - new DeleteTask(this)); - XRE_GetIOMessageLoop()->PostTask( - FROM_HERE, - new DeleteTask(mTransport)); - - // Kick off main-thread shutdown. - gMainThread->PostTask( - FROM_HERE, - NewRunnableMethod(gOpensChild, &TestOpensChild::Close)); + NewRunnableFunction(ShutdownTestOpensOpenedChild, + this, mTransport)); } } // namespace _ipdltest