@@ -282,20 +282,36 @@ void DumpBacktrace(FILE* fp) {
282282void CheckedUvLoopClose (uv_loop_t * loop) {
283283 if (uv_loop_close (loop) == 0 ) return ;
284284
285- auto sym_ctx = NativeSymbolDebuggingContext::New ();
285+ PrintLibuvHandleInformation (loop, stderr);
286+
287+ fflush (stderr);
288+ // Finally, abort.
289+ CHECK (0 && " uv_loop_close() while having open handles" );
290+ }
286291
287- fprintf (stderr, " uv loop at [%p] has active handles\n " , loop);
292+ void PrintLibuvHandleInformation (uv_loop_t * loop, FILE* stream) {
293+ struct Info {
294+ std::unique_ptr<NativeSymbolDebuggingContext> ctx;
295+ FILE* stream;
296+ };
297+
298+ Info info { NativeSymbolDebuggingContext::New (), stream };
299+
300+ fprintf (stream, " uv loop at [%p] has %d active handles\n " ,
301+ loop, loop->active_handles );
288302
289303 uv_walk (loop, [](uv_handle_t * handle, void * arg) {
290- auto sym_ctx = static_cast <NativeSymbolDebuggingContext*>(arg);
304+ Info* info = static_cast <Info*>(arg);
305+ NativeSymbolDebuggingContext* sym_ctx = info->ctx .get ();
306+ FILE* stream = info->stream ;
291307
292- fprintf (stderr , " [%p] %s\n " , handle, uv_handle_type_name (handle->type ));
308+ fprintf (stream , " [%p] %s\n " , handle, uv_handle_type_name (handle->type ));
293309
294310 void * close_cb = reinterpret_cast <void *>(handle->close_cb );
295- fprintf (stderr , " \t Close callback: %p %s\n " ,
311+ fprintf (stream , " \t Close callback: %p %s\n " ,
296312 close_cb, sym_ctx->LookupSymbol (close_cb).Display ().c_str ());
297313
298- fprintf (stderr , " \t Data: %p %s\n " ,
314+ fprintf (stream , " \t Data: %p %s\n " ,
299315 handle->data , sym_ctx->LookupSymbol (handle->data ).Display ().c_str ());
300316
301317 // We are also interested in the first field of what `handle->data`
@@ -309,14 +325,10 @@ void CheckedUvLoopClose(uv_loop_t* loop) {
309325 first_field = *reinterpret_cast <void **>(handle->data );
310326
311327 if (first_field != nullptr ) {
312- fprintf (stderr , " \t (First field): %p %s\n " ,
328+ fprintf (stream , " \t (First field): %p %s\n " ,
313329 first_field, sym_ctx->LookupSymbol (first_field).Display ().c_str ());
314330 }
315- }, sym_ctx.get ());
316-
317- fflush (stderr);
318- // Finally, abort.
319- CHECK (0 && " uv_loop_close() while having open handles" );
331+ }, &info);
320332}
321333
322334std::vector<std::string> NativeSymbolDebuggingContext::GetLoadedLibraries () {
0 commit comments