From 8787d00a8bc341889235861777cc6efc2fdf76b5 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Mon, 17 May 2021 21:28:23 +0530 Subject: [PATCH] src: use HandleScope in StreamReq::Done() Fixes: https://github.com/nodejs/node/issues/38707 --- src/stream_base-inl.h | 1 + test/parallel/test-https-agent-unref-socket.js | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 test/parallel/test-https-agent-unref-socket.js diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index c1590cc957e230..28b0b209922cc2 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -279,6 +279,7 @@ void StreamReq::Done(int status, const char* error_str) { AsyncWrap* async_wrap = GetAsyncWrap(); Environment* env = async_wrap->env(); if (error_str != nullptr) { + v8::HandleScope handle_scope(env->isolate()); async_wrap->object()->Set(env->context(), env->error_string(), OneByteString(env->isolate(), error_str)) diff --git a/test/parallel/test-https-agent-unref-socket.js b/test/parallel/test-https-agent-unref-socket.js new file mode 100644 index 00000000000000..d39e815361910c --- /dev/null +++ b/test/parallel/test-https-agent-unref-socket.js @@ -0,0 +1,13 @@ +'use strict'; + +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); + +const https = require('https'); + +const request = https.get('https://www.google.com'); + +request.on('socket', (socket) => { + socket.unref(); +});