diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-06-07 22:07:02 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-06-13 12:23:36 +0200 |
commit | aa2304b8d5c53ba2d9710d8b8ed4482f3cbd1192 (patch) | |
tree | 4bd93c9dd7f8a5fa0e04c4897b8e0aa7c1075225 /test/addons | |
parent | 8e2d33f15620013de504c1181641aa961906f436 (diff) | |
download | android-node-v8-aa2304b8d5c53ba2d9710d8b8ed4482f3cbd1192.tar.gz android-node-v8-aa2304b8d5c53ba2d9710d8b8ed4482f3cbd1192.tar.bz2 android-node-v8-aa2304b8d5c53ba2d9710d8b8ed4482f3cbd1192.zip |
worker,src: display remaining handles if `uv_loop_close` fails
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 <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/addons')
-rw-r--r-- | test/addons/uv-handle-leak/binding.cc | 48 | ||||
-rw-r--r-- | test/addons/uv-handle-leak/binding.gyp | 9 | ||||
-rw-r--r-- | test/addons/uv-handle-leak/test.js | 23 |
3 files changed, 80 insertions, 0 deletions
diff --git a/test/addons/uv-handle-leak/binding.cc b/test/addons/uv-handle-leak/binding.cc new file mode 100644 index 0000000000..c2e5f0bf27 --- /dev/null +++ b/test/addons/uv-handle-leak/binding.cc @@ -0,0 +1,48 @@ +#include <node.h> +#include <v8.h> +#include <uv.h> + +using v8::Context; +using v8::FunctionCallbackInfo; +using v8::Isolate; +using v8::Local; +using v8::Object; +using v8::Value; + +// Give these things names in the public namespace so that we can see +// them show up in symbol dumps. +void CloseCallback(uv_handle_t* handle) {} + +class ExampleOwnerClass { + public: + virtual ~ExampleOwnerClass() {} +}; + +ExampleOwnerClass example_instance; + +void LeakHandle(const FunctionCallbackInfo<Value>& args) { + Isolate* isolate = args.GetIsolate(); + Local<Context> context = isolate->GetCurrentContext(); + uv_loop_t* loop = node::GetCurrentEventLoop(isolate); + assert(loop != nullptr); + + uv_timer_t* leaked_timer = new uv_timer_t; + leaked_timer->close_cb = CloseCallback; + + if (args[0]->IsNumber()) { + leaked_timer->data = + reinterpret_cast<void*>(args[0]->IntegerValue(context).FromJust()); + } else { + leaked_timer->data = &example_instance; + } + + uv_timer_init(loop, leaked_timer); + uv_timer_start(leaked_timer, [](uv_timer_t*){}, 1000, 1000); + uv_unref(reinterpret_cast<uv_handle_t*>(leaked_timer)); +} + +void Initialize(v8::Local<v8::Object> exports) { + NODE_SET_METHOD(exports, "leakHandle", LeakHandle); +} + +NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize) diff --git a/test/addons/uv-handle-leak/binding.gyp b/test/addons/uv-handle-leak/binding.gyp new file mode 100644 index 0000000000..7ede63d94a --- /dev/null +++ b/test/addons/uv-handle-leak/binding.gyp @@ -0,0 +1,9 @@ +{ + 'targets': [ + { + 'target_name': 'binding', + 'defines': [ 'V8_DEPRECATION_WARNINGS=1' ], + 'sources': [ 'binding.cc' ] + } + ] +} diff --git a/test/addons/uv-handle-leak/test.js b/test/addons/uv-handle-leak/test.js new file mode 100644 index 0000000000..73d40ca799 --- /dev/null +++ b/test/addons/uv-handle-leak/test.js @@ -0,0 +1,23 @@ +'use strict'; +const common = require('../../common'); +const bindingPath = require.resolve(`./build/${common.buildType}/binding`); +const binding = require(bindingPath); + +// This tests checks that addons may leak libuv handles until process exit. +// It’s really not a good idea to do so, but it tests existing behaviour +// that likely can never be removed for backwards compatibility. + +// This has a sibling test in test/abort/ which checks output for failures +// from workers. + +try { + // We don’t want to run this in Workers because they do actually enforce + // a clean-exit policy. + const { isMainThread } = require('worker_threads'); + if (!isMainThread) + common.skip('Cannot run test in environment with clean-exit policy'); +} catch {} + +binding.leakHandle(); +binding.leakHandle(0); +binding.leakHandle(1); |