diff --git a/doc/api/report.md b/doc/api/report.md index 90ec1b7f1807e8..40e3050ee4d24d 100644 --- a/doc/api/report.md +++ b/doc/api/report.md @@ -190,13 +190,13 @@ is provided below for reference. "details": "" }, { - "repeat": 0, - "firesInMsFromNow": 94403548320796, - "expired": true, "type": "timer", "is_active": false, "is_referenced": false, - "address": "0x00007fff5fbfeab0" + "address": "0x00007fff5fbfeab0", + "repeat": 0, + "firesInMsFromNow": 94403548320796, + "expired": true }, { "type": "check", @@ -229,36 +229,36 @@ is provided below for reference. "address": "0x000000010188f2e0" }, { + "type": "tty", + "is_active": false, + "is_referenced": true, + "address": "0x000055b581db0e18", "width": 204, "height": 55, "fd": 17, "writeQueueSize": 0, "readable": true, - "writable": true, - "type": "tty", - "is_active": false, - "is_referenced": true, - "address": "0x000055b581db0e18" + "writable": true }, { - "signum": 28, - "signal": "SIGWINCH", "type": "signal", "is_active": true, "is_referenced": false, - "address": "0x000055b581d80010" + "address": "0x000055b581d80010", + "signum": 28, + "signal": "SIGWINCH" }, { + "type": "tty", + "is_active": true, + "is_referenced": true, + "address": "0x000055b581df59f8", "width": 204, "height": 55, "fd": 19, "writeQueueSize": 0, "readable": true, - "writable": true, - "type": "tty", - "is_active": true, - "is_referenced": true, - "address": "0x000055b581df59f8" + "writable": true }, { "type": "loop", diff --git a/src/node_report_utils.cc b/src/node_report_utils.cc index 81fdeda0405ea4..24f3b6175d5ad6 100644 --- a/src/node_report_utils.cc +++ b/src/node_report_utils.cc @@ -126,6 +126,11 @@ void WalkHandle(uv_handle_t* h, void* arg) { uv_any_handle* handle = reinterpret_cast(h); writer->json_start(); + writer->json_keyvalue("type", type); + writer->json_keyvalue("is_active", static_cast(uv_is_active(h))); + writer->json_keyvalue("is_referenced", static_cast(uv_has_ref(h))); + writer->json_keyvalue("address", + ValueToHexString(reinterpret_cast(h))); switch (h->type) { case UV_FS_EVENT: @@ -216,11 +221,6 @@ void WalkHandle(uv_handle_t* h, void* arg) { static_cast(uv_is_writable(&handle->stream))); } - writer->json_keyvalue("type", type); - writer->json_keyvalue("is_active", static_cast(uv_is_active(h))); - writer->json_keyvalue("is_referenced", static_cast(uv_has_ref(h))); - writer->json_keyvalue("address", - ValueToHexString(reinterpret_cast(h))); writer->json_end(); } diff --git a/test/report/test-report-uv-handles.js b/test/report/test-report-uv-handles.js index f03791f13461bc..51677168947bf4 100644 --- a/test/report/test-report-uv-handles.js +++ b/test/report/test-report-uv-handles.js @@ -97,6 +97,22 @@ if (process.argv[2] === 'child') { const reports = helper.findReports(child.pid, tmpdir.path); assert.deepStrictEqual(reports, [], report_msg, reports); + // Test libuv handle key order + { + const get_libuv = /"libuv":\s\[([\s\S]*?)\]/gm; + const get_handle_inner = /{([\s\S]*?),*?}/gm; + const libuv_handles_str = get_libuv.exec(stdout)[1]; + const libuv_handles_array = libuv_handles_str.match(get_handle_inner); + for (const i of libuv_handles_array) { + // Exclude nested structure + if (i.includes('type')) { + const handle_keys = i.match(/(".*"):/gm); + assert(handle_keys[0], 'type'); + assert(handle_keys[1], 'is_active'); + } + } + } + const report = JSON.parse(stdout); const prefix = common.isWindows ? '\\\\?\\' : ''; const expected_filename = `${prefix}${__filename}`;