Skip to content

Commit a2384e5

Browse files
committed
Additional sanity checks:
- don't sample a dead isolate - only try to retrieve an async ID when there's a context
1 parent e7ac5bc commit a2384e5

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

bindings/profilers/wall.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,9 @@ void SignalHandler::HandleProfilerSignal(int sig,
291291
return;
292292
}
293293
auto isolate = Isolate::GetCurrent();
294+
if (!isolate || isolate->IsDead()) {
295+
return;
296+
}
294297
WallProfiler* prof = g_profilers.GetProfiler(isolate);
295298

296299
if (!prof) {

bindings/profilers/wall.hh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,18 @@ class WallProfiler : public Nan::ObjectWrap {
155155
int64_t GetAsyncId(v8::Isolate* isolate) const {
156156
if (gcCount > 0) {
157157
return gcAsyncId;
158+
} else if (isolate->InContext()) {
159+
return static_cast<int64_t>(node::AsyncHooksGetExecutionAsyncId(isolate));
158160
}
159-
return static_cast<int64_t>(node::AsyncHooksGetExecutionAsyncId(isolate));
161+
return -1;
160162
}
161163

162164
void OnGCStart(v8::Isolate* isolate) {
163-
if (gcCount++ == 0) {
164-
gcAsyncId =
165-
static_cast<int64_t>(node::AsyncHooksGetExecutionAsyncId(isolate));
165+
if (gcCount == 0) {
166+
gcAsyncId = GetAsyncId(isolate);
167+
gcCount = 1;
168+
} else {
169+
++gcCount;
166170
}
167171
}
168172

0 commit comments

Comments
 (0)