From d06ad0d4f0b2143fc3eef41b678a8ee5cbc18290 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 21 Nov 2017 12:39:55 +0100 Subject: [PATCH] http2: don't call into JS from GC Calling into JS land from GC is not allowed, so delay the resolution of pending pings when a session is destroyed. Backport-PR-URL: https://github.com/nodejs/node/pull/18050 PR-URL: https://github.com/nodejs/node/pull/17183 Reviewed-By: James M Snell Reviewed-By: Franziska Hinkelmann Reviewed-By: Anatoli Papirovski --- src/node_http2.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/node_http2.cc b/src/node_http2.cc index 0747789786b028..2ed5cbb4a3dc59 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -406,7 +406,11 @@ void Http2Session::Close() { while (!outstanding_pings_.empty()) { Http2Session::Http2Ping* ping = PopPing(); - ping->Done(false); + // Since this method may be called from GC, calling into JS directly + // is not allowed. + env()->SetImmediate([](Environment* env, void* data) { + static_cast(data)->Done(false); + }, static_cast(ping)); } Stop();