From 20aae9d94adca943d9bea41eecddd370ae04f067 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 21 Sep 2019 02:15:32 +0200 Subject: [PATCH 1/2] src: fix closing weak `HandleWrap`s on GC In 0af62aae07ccbb3783030367ffe4, this was overlooked, with it possibly leading to hard crashes. Refs: https://github.com/nodejs/node/pull/29317 --- src/handle_wrap.cc | 4 ++-- test/sequential/test-performance-eventloopdelay.js | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 8ed6b2948dffd9..888640e9493d8e 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -72,11 +72,11 @@ void HandleWrap::Close(Local close_callback) { if (state_ != kInitialized) return; - CHECK_EQ(false, persistent().IsEmpty()); uv_close(handle_, OnClose); state_ = kClosing; - if (!close_callback.IsEmpty() && close_callback->IsFunction()) { + if (!close_callback.IsEmpty() && close_callback->IsFunction() && + !persistent().IsEmpty()) { object()->Set(env()->context(), env()->handle_onclose_symbol(), close_callback).Check(); diff --git a/test/sequential/test-performance-eventloopdelay.js b/test/sequential/test-performance-eventloopdelay.js index 82f47b6fb29c47..517dc56c86a8e4 100644 --- a/test/sequential/test-performance-eventloopdelay.js +++ b/test/sequential/test-performance-eventloopdelay.js @@ -1,3 +1,4 @@ +// Flags: --expose-gc 'use strict'; const common = require('../common'); @@ -97,3 +98,5 @@ const { } spinAWhile(); } + +process.on('exit', global.gc); From 9e45a591b82a490ef3b3803eab44acc51f883688 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 21 Sep 2019 12:48:09 +0200 Subject: [PATCH 2/2] fixup! src: fix closing weak `HandleWrap`s on GC --- test/sequential/test-performance-eventloopdelay.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/sequential/test-performance-eventloopdelay.js b/test/sequential/test-performance-eventloopdelay.js index 517dc56c86a8e4..7b9527b3863905 100644 --- a/test/sequential/test-performance-eventloopdelay.js +++ b/test/sequential/test-performance-eventloopdelay.js @@ -99,4 +99,6 @@ const { spinAWhile(); } +// Make sure that the histogram instances can be garbage-collected without +// and not just implictly destroyed when the Environment is torn down. process.on('exit', global.gc);