Skip to content

Commit d532d74

Browse files
trevnorrisMylesBorins
authored andcommitted
async_wrap: clear destroy_ids vector
After processing all the callbacks in the destroy_ids vector make sure to clear() it otherwise the DestroyIdsCb() won't run again. PR-URL: #10400 Fixes: b49b496 "async_wrap: call destroy() callback in uv_idle_t" Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent cfa1b5a commit d532d74

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/async-wrap.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ void AsyncWrap::DestroyIdsCb(uv_idle_t* handle) {
199199

200200
TryCatch try_catch(env->isolate());
201201

202-
for (auto current_id : *env->destroy_ids_list()) {
202+
std::vector<int64_t> destroy_ids_list;
203+
destroy_ids_list.swap(*env->destroy_ids_list());
204+
for (auto current_id : destroy_ids_list) {
203205
// Want each callback to be cleaned up after itself, instead of cleaning
204206
// them all up after the while() loop completes.
205207
HandleScope scope(env->isolate());
@@ -212,6 +214,8 @@ void AsyncWrap::DestroyIdsCb(uv_idle_t* handle) {
212214
FatalException(env->isolate(), try_catch);
213215
}
214216
}
217+
218+
env->destroy_ids_list()->clear();
215219
}
216220

217221

test/parallel/test-async-wrap-uid.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@ const fs = require('fs');
55
const assert = require('assert');
66
const async_wrap = process.binding('async_wrap');
77

8+
// Give the event loop time to clear out the final uv_close().
9+
var si_cntr = 3;
10+
process.on('beforeExit', () => {
11+
if (--si_cntr > 0) setImmediate(() => {});
12+
});
13+
814
const storage = new Map();
9-
async_wrap.setupHooks({ init, pre, post });
15+
async_wrap.setupHooks({ init, pre, post, destroy });
1016
async_wrap.enable();
1117

1218
function init(uid) {
1319
storage.set(uid, {
1420
init: true,
1521
pre: false,
1622
post: false,
23+
destroy: false,
1724
});
1825
}
1926

@@ -25,6 +32,10 @@ function post(uid) {
2532
storage.get(uid).post = true;
2633
}
2734

35+
function destroy(uid) {
36+
storage.get(uid).destroy = true;
37+
}
38+
2839
fs.access(__filename, function(err) {
2940
assert.ifError(err);
3041
});
@@ -46,6 +57,7 @@ process.once('exit', function() {
4657
init: true,
4758
pre: true,
4859
post: true,
60+
destroy: true,
4961
});
5062
}
5163
});

0 commit comments

Comments
 (0)