Skip to content

Commit e6e05ed

Browse files
committed
fix: Deadlock under load
1 parent e0f143b commit e6e05ed

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

module.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ void CaptureStackTraces(const FunctionCallbackInfo<Value> &args) {
369369

370370
std::vector<ThreadResult> results;
371371

372+
std::vector<std::future<ThreadResult>> futures;
372373
{
373-
std::vector<std::future<ThreadResult>> futures;
374374
std::lock_guard<std::mutex> lock(threads_mutex);
375375
for (auto &thread : threads) {
376376
auto thread_isolate = thread.first;
@@ -393,10 +393,13 @@ void CaptureStackTraces(const FunctionCallbackInfo<Value> &args) {
393393
},
394394
std::cref(thread_info.async_store)));
395395
}
396+
}
396397

397-
for (auto &fut : futures) {
398-
results.emplace_back(fut.get());
399-
}
398+
// Wait for all futures to complete AFTER releasing the lock
399+
// to avoid deadlock with ThreadPoll trying to acquire the same mutex
400+
// https://github.com/getsentry/sentry-javascript-node-native-stacktrace/issues/35
401+
for (auto &fut : futures) {
402+
results.emplace_back(fut.get());
400403
}
401404

402405
auto current_context = capture_from_isolate->GetCurrentContext();

0 commit comments

Comments
 (0)