From dfc81963e246bed16bd0f0deeae6e1a17ddfa969 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Tue, 5 Dec 2023 09:56:08 -0800 Subject: [PATCH] Persist the actorId for ActorSqliteHooks Fixes: https://github.com/cloudflare/workerd/issues/1386 --- src/workerd/server/server.c++ | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/workerd/server/server.c++ b/src/workerd/server/server.c++ index c1026e98d39..2f2419256df 100644 --- a/src/workerd/server/server.c++ +++ b/src/workerd/server/server.c++ @@ -1741,9 +1741,14 @@ public: return config.tryGet() .map([&](const Durable& d) -> kj::Own { KJ_IF_SOME(as, channels.actorStorage) { + // The idPtr can end up being freed if the Actor gets hibernated so we need + // to create a copy that is ensured to live as long as the ActorSqliteHooks + // instance we're creating here. + // TODO(cleanup): Is there a better way to handle the ActorKey in general here? + auto idStr = kj::str(idPtr); auto sqliteHooks = kj::heap(channels.alarmScheduler, ActorKey{ - .uniqueKey = d.uniqueKey, .actorId = idPtr - }); + .uniqueKey = d.uniqueKey, .actorId = idStr + }).attach(kj::mv(idStr)); auto db = kj::heap(*as, kj::Path({d.uniqueKey, kj::str(idPtr, ".sqlite")}),