From aa2304b8d5c53ba2d9710d8b8ed4482f3cbd1192 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 7 Jun 2018 22:07:02 +0200 Subject: worker,src: display remaining handles if `uv_loop_close` fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Right now, we crash the process if there are handles remaining on the event loop when we exit (except for the main thread). This does not provide a lot of information about causes, though; in particular, we don’t show which handles are pending and who own them. This patch adds debug output to these cases to help with the situation. PR-URL: https://github.com/nodejs/node/pull/21238 Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: James M Snell Reviewed-By: Gus Caplan Reviewed-By: Ben Noordhuis Reviewed-By: Benjamin Gruenbaum Reviewed-By: Colin Ihrig --- test/abort/test-addon-uv-handle-leak.js | 97 +++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 test/abort/test-addon-uv-handle-leak.js (limited to 'test/abort') diff --git a/test/abort/test-addon-uv-handle-leak.js b/test/abort/test-addon-uv-handle-leak.js new file mode 100644 index 0000000000..3944cb79c7 --- /dev/null +++ b/test/abort/test-addon-uv-handle-leak.js @@ -0,0 +1,97 @@ +// Flags: --experimental-worker +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); +const cp = require('child_process'); +const { Worker } = require('worker_threads'); + +// This is a sibling test to test/addons/uv-handle-leak. + +const bindingPath = path.resolve( + __dirname, '..', 'addons', 'uv-handle-leak', 'build', + `${common.buildType}/binding.node`); + +if (!fs.existsSync(bindingPath)) + common.skip('binding not built yet'); + +if (process.argv[2] === 'child') { + new Worker(` + const binding = require(${JSON.stringify(bindingPath)}); + + binding.leakHandle(); + binding.leakHandle(0); + binding.leakHandle(0x42); + `, { eval: true }); +} else { + const child = cp.spawnSync(process.execPath, + ['--experimental-worker', __filename, 'child']); + const stderr = child.stderr.toString(); + + assert.strictEqual(child.stdout.toString(), ''); + + const lines = stderr.split('\n'); + + let state = 'initial'; + + // parse output that is formatted like this: + + // uv loop at [0x559b65ed5770] has active handles + // [0x7f2de0018430] timer + // Close callback: 0x7f2df31de220 CloseCallback(uv_handle_s*) [...] + // Data: 0x7f2df33df140 example_instance [...] + // (First field): 0x7f2df33dedc0 vtable for ExampleOwnerClass [...] + // [0x7f2de000b870] timer + // Close callback: 0x7f2df31de220 CloseCallback(uv_handle_s*) [...] + // Data: (nil) + // [0x7f2de000b910] timer + // Close callback: 0x7f2df31de220 CloseCallback(uv_handle_s*) [...] + // Data: 0x42 + + if (!(common.isFreeBSD || + common.isAIX || + (common.isLinux && !common.isGlibc()) || + common.isWindows)) { + assert(stderr.includes('ExampleOwnerClass'), stderr); + assert(stderr.includes('CloseCallback'), stderr); + assert(stderr.includes('example_instance'), stderr); + } + + while (lines.length > 0) { + const line = lines.shift().trim(); + + switch (state) { + case 'initial': + assert(/^uv loop at \[.+\] has active handles$/.test(line), line); + state = 'handle-start'; + break; + case 'handle-start': + if (/Assertion .+ failed/.test(line)) { + state = 'done'; + break; + } + assert(/^\[.+\] timer$/.test(line), line); + state = 'close-callback'; + break; + case 'close-callback': + assert(/^Close callback:/.test(line), line); + state = 'data'; + break; + case 'data': + assert(/^Data: .+$/.test(line), line); + state = 'maybe-first-field'; + break; + case 'maybe-first-field': + if (/^\(First field\)$/.test(line)) { + lines.unshift(line); + state = 'handle-start'; + break; + } + state = 'maybe-first-field'; + break; + case 'done': + break; + } + } +} -- cgit v1.2.3