Skip to content

Commit 6b02637

Browse files
authored
[jsg] assert active deferred queue state (#5409)
1 parent 6fd515f commit 6b02637

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/workerd/jsg/setup.c++

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ void IsolateBase::jsgGetMemoryInfo(MemoryTracker& tracker) const {
231231

232232
void IsolateBase::deferDestruction(Item item) {
233233
KJ_REQUIRE_NONNULL(ptr, "tried to defer destruction after V8 isolate was destroyed");
234+
if (queueState != QueueState::ACTIVE) {
235+
KJ_LOG(ERROR, "tried to defer destruction during isolate shutdown", queueState,
236+
kj::getStackTrace());
237+
}
234238
queue.lockExclusive()->push(kj::mv(item));
235239
}
236240

@@ -458,6 +462,8 @@ v8::Local<v8::FunctionTemplate> IsolateBase::getOpaqueTemplate(v8::Isolate* isol
458462
}
459463

460464
void IsolateBase::dropWrappers(kj::FunctionParam<void()> drop) {
465+
KJ_REQUIRE(queueState == QueueState::ACTIVE);
466+
queueState = QueueState::DROPPING;
461467
// Delete all wrappers.
462468
jsg::runInV8Stack([&](jsg::V8StackScope& stackScope) {
463469
v8::Locker lock(ptr);
@@ -480,6 +486,7 @@ void IsolateBase::dropWrappers(kj::FunctionParam<void()> drop) {
480486

481487
// Destroy all wrappers.
482488
heapTracer.clearWrappers();
489+
queueState = QueueState::DROPPED;
483490
});
484491
}
485492

src/workerd/jsg/setup.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ class IsolateBase {
365365
const kj::MutexGuarded<BatchQueue<Item>> queue{
366366
DESTRUCTION_QUEUE_INITIAL_SIZE, DESTRUCTION_QUEUE_MAX_CAPACITY};
367367

368+
enum QueueState { ACTIVE, DROPPING, DROPPED };
369+
QueueState queueState = ACTIVE;
370+
368371
struct CodeBlockInfo {
369372
size_t size = 0;
370373
kj::Maybe<v8::JitCodeEvent::CodeType> type;

0 commit comments

Comments
 (0)