Skip to content

Commit 4d31c19

Browse files
Fixed propagation of async hook IDs through callbacks (#1511)
1 parent efee5f0 commit 4d31c19

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/macros.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ inline bool OtherIsInt(Napi::Number source) {
125125
if ((argc != 0) && (passed_argv != NULL)) {\
126126
args.assign(passed_argv, passed_argv + argc);\
127127
}\
128-
Napi::Value res = (callback).MakeCallback(Napi::Value(context), args); \
128+
Napi::Value res = (callback).Call(Napi::Value(context), args); \
129129
if (res.IsEmpty()) return __VA_ARGS__;
130130

131131
#define WORK_DEFINITION(name) \

test/async_calls.test.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"use strict"
2+
3+
var sqlite3 = require('..');
4+
const assert = require("assert");
5+
const { createHook, executionAsyncId } = require("async_hooks");
6+
7+
8+
describe('async_hooks', function() {
9+
let db;
10+
let dbId;
11+
let asyncHook;
12+
13+
beforeEach(function() {
14+
db = new sqlite3.Database(':memory:');
15+
16+
asyncHook = createHook({
17+
init(asyncId, type) {
18+
if (dbId == null && type.startsWith("sqlite3.")) {
19+
dbId = asyncId;
20+
}
21+
}
22+
}).enable();
23+
});
24+
25+
it('should support performance measuring with async hooks', function(done) {
26+
db.run("DROP TABLE user", () => {
27+
const cbId = executionAsyncId();
28+
assert.strictEqual(cbId, dbId);
29+
done();
30+
});
31+
});
32+
33+
afterEach(function() {
34+
if (asyncHook != null) {
35+
asyncHook.disable();
36+
}
37+
dbId = null;
38+
if (db != null) {
39+
db.close();
40+
}
41+
});
42+
});

0 commit comments

Comments
 (0)