Skip to content

Commit

Permalink
SQLite-backed DOs: check actor brokenness before starting implicit tr…
Browse files Browse the repository at this point in the history
…ansactions
  • Loading branch information
jclee committed Oct 11, 2024
1 parent 39da3c4 commit c3b0c07
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/workerd/io/actor-sqlite-test.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1136,5 +1136,26 @@ KJ_TEST("rolling back nested transaction leaves deferred alarm deletion in expec
KJ_ASSERT(expectSync(test.getAlarm()) == kj::none);
}

KJ_TEST("database write operations check for brokenness") {
ActorSqliteTest test({.monitorOutputGate = false});

auto promise = test.gate.onBroken();

// Break gate
test.put("foo", "bar");
test.pollAndExpectCalls({"commit"})[0]->reject(KJ_EXCEPTION(FAILED, "a_rejected_commit"));

KJ_EXPECT_THROW_MESSAGE("a_rejected_commit", promise.wait(test.ws));

// We don't actually set ActorSqlite's brokenness until the taskFailed handler runs...
test.ws.poll();

// Try making a write operation to the database, expecting it to throw the broken message via
// the onWrite handler:
KJ_EXPECT_THROW_MESSAGE(
"a_rejected_commit", test.db.run("CREATE TABLE IF NOT EXISTS counter (count INTEGER)"));
test.pollAndExpectCalls({});
}

} // namespace
} // namespace workerd
1 change: 1 addition & 0 deletions src/workerd/io/actor-sqlite.c++
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ void ActorSqlite::ExplicitTxn::rollbackImpl() noexcept(false) {
}

void ActorSqlite::onWrite() {
requireNotBroken();
if (currentTxn.is<NoTxn>()) {
auto txn = kj::heap<ImplicitTxn>(*this);

Expand Down

0 comments on commit c3b0c07

Please sign in to comment.