Skip to content

Commit

Permalink
async_wrap: clear destroy_ids vector
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
trevnorris authored and evanlucas committed Jan 3, 2017
1 parent 5e5b1f8 commit d1843ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/async-wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ void AsyncWrap::DestroyIdsCb(uv_idle_t* handle) {

TryCatch try_catch(env->isolate());

for (auto current_id : *env->destroy_ids_list()) {
std::vector<int64_t> destroy_ids_list;
destroy_ids_list.swap(*env->destroy_ids_list());
for (auto current_id : destroy_ids_list) {
// Want each callback to be cleaned up after itself, instead of cleaning
// them all up after the while() loop completes.
HandleScope scope(env->isolate());
Expand All @@ -212,6 +214,8 @@ void AsyncWrap::DestroyIdsCb(uv_idle_t* handle) {
FatalException(env->isolate(), try_catch);
}
}

env->destroy_ids_list()->clear();
}


Expand Down
14 changes: 13 additions & 1 deletion test/parallel/test-async-wrap-uid.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@ const fs = require('fs');
const assert = require('assert');
const async_wrap = process.binding('async_wrap');

// Give the event loop time to clear out the final uv_close().
var si_cntr = 3;
process.on('beforeExit', () => {
if (--si_cntr > 0) setImmediate(() => {});
});

const storage = new Map();
async_wrap.setupHooks({ init, pre, post });
async_wrap.setupHooks({ init, pre, post, destroy });
async_wrap.enable();

function init(uid) {
storage.set(uid, {
init: true,
pre: false,
post: false,
destroy: false,
});
}

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

function destroy(uid) {
storage.get(uid).destroy = true;
}

fs.access(__filename, function(err) {
assert.ifError(err);
});
Expand All @@ -46,6 +57,7 @@ process.once('exit', function() {
init: true,
pre: true,
post: true,
destroy: true,
});
}
});

0 comments on commit d1843ec

Please sign in to comment.