Skip to content

Commit 181837b

Browse files
committed
Merge #116: shutdown bugfix: destroy RPC system before running cleanup callbacks
2350843 shutdown bugfix: destroy RPC system before running cleanup callbacks (Ryan Ofsky) Pull request description: Fixes #115 Top commit has no ACKs. Tree-SHA512: 1ec3a98ffbcb7e5517ce6130c011b0defa6ca6a31c18ccd42f4c69259ad9f08211e75e6d89387cb70d4af0c657cc7c2d0a3e0c2425301db2d33442b2842c0564
2 parents a4ac424 + 2350843 commit 181837b

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

include/mp/proxy-io.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ class Connection
333333
LoggingErrorHandler m_error_handler{m_loop};
334334
kj::TaskSet m_on_disconnect{m_error_handler};
335335
::capnp::TwoPartyVatNetwork m_network;
336-
::capnp::RpcSystem<::capnp::rpc::twoparty::VatId> m_rpc_system;
336+
std::optional<::capnp::RpcSystem<::capnp::rpc::twoparty::VatId>> m_rpc_system;
337337

338338
// ThreadMap interface client, used to create a remote server thread when an
339339
// client IPC call is being made for the first time from a new thread.
@@ -567,7 +567,7 @@ std::unique_ptr<ProxyClient<InitInterface>> ConnectStream(EventLoop& loop, int f
567567
auto stream =
568568
loop.m_io_context.lowLevelProvider->wrapSocketFd(fd, kj::LowLevelAsyncIoProvider::TAKE_OWNERSHIP);
569569
connection = std::make_unique<Connection>(loop, kj::mv(stream));
570-
init_client = connection->m_rpc_system.bootstrap(ServerVatId().vat_id).castAs<InitInterface>();
570+
init_client = connection->m_rpc_system->bootstrap(ServerVatId().vat_id).castAs<InitInterface>();
571571
Connection* connection_ptr = connection.get();
572572
connection->onDisconnect([&loop, connection_ptr] {
573573
loop.log() << "IPC client: unexpected network disconnect.";

src/mp/proxy.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ void LoggingErrorHandler::taskFailed(kj::Exception&& exception)
4848

4949
Connection::~Connection()
5050
{
51+
// Shut down RPC system first, since this will garbage collect Server
52+
// objects that were not freed before the connection was closed, some of
53+
// which may call addAsyncCleanup and add more cleanup callbacks which can
54+
// run below.
55+
m_rpc_system.reset();
56+
5157
// ProxyClient cleanup handlers are in sync list, and ProxyServer cleanup
5258
// handlers are in the async list.
5359
//

test/mp/test/test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ KJ_TEST("Call FooInterface methods")
2525

2626
auto connection_client = std::make_unique<Connection>(loop, kj::mv(pipe.ends[0]));
2727
auto foo_client = std::make_unique<ProxyClient<messages::FooInterface>>(
28-
connection_client->m_rpc_system.bootstrap(ServerVatId().vat_id).castAs<messages::FooInterface>(),
28+
connection_client->m_rpc_system->bootstrap(ServerVatId().vat_id).castAs<messages::FooInterface>(),
2929
connection_client.get(), /* destroy_connection= */ false);
3030
foo_promise.set_value(std::move(foo_client));
3131
disconnect_client = [&] { loop.sync([&] { connection_client.reset(); }); };

0 commit comments

Comments
 (0)