async_hooks: avoid resource reuse by FileHandle · nodejs/node@478f1e7 · GitHub
Skip to content

Commit 478f1e7

Browse files
FlarnaMylesBorins
authored andcommitted
async_hooks: avoid resource reuse by FileHandle
Wrap reused read_wrap in a unique async resource to ensure that executionAsyncResource() is not ambiguous. PR-URL: #31972 Refs: #30959 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
1 parent 893e918 commit 478f1e7

4 files changed

Lines changed: 72 additions & 9 deletions

File tree

src/async_wrap.cc

Lines changed: 1 addition & 5 deletions

src/async_wrap.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ class AsyncWrap : public BaseObject {
170170
double execution_async_id = kInvalidAsyncId,
171171
bool silent = false);
172172

173-
void AsyncReset(double execution_async_id = kInvalidAsyncId,
174-
bool silent = false);
175-
176173
// Only call these within a valid HandleScope.
177174
v8::MaybeLocal<v8::Value> MakeCallback(const v8::Local<v8::Function> cb,
178175
int argc,

src/node_file.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,12 @@ int FileHandle::ReadStart() {
369369
if (freelist.size() > 0) {
370370
read_wrap = std::move(freelist.back());
371371
freelist.pop_back();
372-
read_wrap->AsyncReset();
372+
// Use a fresh async resource.
373+
// Lifetime is ensured via AsyncWrap::resource_.
374+
Local<Object> resource = Object::New(env()->isolate());
375+
resource->Set(
376+
env()->context(), env()->handle_string(), read_wrap->object());
377+
read_wrap->AsyncReset(resource);
373378
read_wrap->file_handle_ = this;
374379
} else {
375380
Local<Object> wrap_obj;
Lines changed: 65 additions & 0 deletions

0 commit comments

Comments
 (0)