diff --git a/src/node_http2.cc b/src/node_http2.cc index b439ae588a7756..52883dcd644bfc 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();