From da3a9486a868949604557ffd0d7adf2d654d5b3f Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sun, 24 Jan 2021 10:00:57 -0800 Subject: [PATCH] buffer: avoid creating the backing store in the thread Fixes: https://github.com/nodejs/node/issues/37030 PR-URL: https://github.com/nodejs/node/pull/37052 Reviewed-By: Anna Henningsen Reviewed-By: Antoine du Hamel Reviewed-By: Rich Trott --- src/node_blob.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node_blob.cc b/src/node_blob.cc index b147b8764a7668..0b18bbce138e35 100644 --- a/src/node_blob.cc +++ b/src/node_blob.cc @@ -254,8 +254,6 @@ void FixedSizeBlobCopyJob::AfterThreadPoolWork(int status) { } void FixedSizeBlobCopyJob::DoThreadPoolWork() { - Environment* env = AsyncWrap::env(); - destination_ = ArrayBuffer::NewBackingStore(env->isolate(), length_); unsigned char* dest = static_cast(destination_->Data()); if (length_ > 0) { size_t total = 0; @@ -314,6 +312,8 @@ void FixedSizeBlobCopyJob::Run(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); FixedSizeBlobCopyJob* job; ASSIGN_OR_RETURN_UNWRAP(&job, args.Holder()); + job->destination_ = + ArrayBuffer::NewBackingStore(env->isolate(), job->length_); if (job->mode() == FixedSizeBlobCopyJob::Mode::ASYNC) return job->ScheduleWork();