From 4e3353223e5a3f7e9a0ab2cdf22ed1a36fc83a3c 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 PR-URL: https://github.com/nodejs/node/pull/38720 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen --- 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..b2863a74d817d4 --- /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://example.com'); + +request.on('socket', (socket) => { + socket.unref(); +});