@@ -4012,6 +4012,10 @@ void *node_loader_impl_register(void *node_impl_ptr, void *env_ptr, void *functi
40124012 node_impl->extra_active_handles .store (0 );
40134013 node_impl->event_loop_empty .store (false );
40144014
4015+ #if (!defined(NDEBUG) || defined(DEBUG) || defined(_DEBUG) || defined(__DEBUG) || defined(__DEBUG__))
4016+ node_loader_impl_print_handles (node_impl);
4017+ #endif
4018+
40154019 /* On Windows, hook node extension loading mechanism in order to patch extensions linked to node.exe */
40164020#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1200)
40174021 node_loader_node_dll_handle = GetModuleHandle (NODEJS_LIBRARY_NAME);
@@ -4990,17 +4994,30 @@ static inline int uv__queue_empty(const struct node_loader_impl_uv__queue *q)
49904994 return q == q->next ;
49914995}
49924996
4993- int64_t node_loader_impl_async_handles_count (loader_impl_node node_impl)
4997+ int64_t node_loader_impl_async_closing_handles_count (loader_impl_node node_impl)
49944998{
4995- int64_t active_handles = (int64_t )node_impl->thread_loop ->active_handles +
4996- (int64_t )node_impl->thread_loop ->active_reqs .count +
49974999#if defined(WIN32) || defined(_WIN32)
4998- (int64_t )(node_impl->thread_loop ->pending_reqs_tail != NULL ) +
4999- (int64_t )(node_impl->thread_loop ->endgame_handles != NULL );
5000+ return (int64_t )(node_impl->thread_loop ->pending_reqs_tail != NULL ) +
5001+ (int64_t )(node_impl->thread_loop ->endgame_handles != NULL );
50005002#else
5001- (int64_t )(!uv__queue_empty ((const struct node_loader_impl_uv__queue *)(&node_impl->thread_loop ->pending_queue ))) +
5002- (int64_t )(node_impl->thread_loop ->closing_handles != NULL );
5003+ union
5004+ {
5005+ void *data;
5006+ const struct node_loader_impl_uv__queue *ptr;
5007+ } uv__queue_cast;
5008+
5009+ uv__queue_cast.data = (void *)&node_impl->thread_loop ->pending_queue ;
5010+
5011+ return (int64_t )(!uv__queue_empty (uv__queue_cast.ptr )) +
5012+ (int64_t )(node_impl->thread_loop ->closing_handles != NULL );
50035013#endif
5014+ }
5015+
5016+ int64_t node_loader_impl_async_handles_count (loader_impl_node node_impl)
5017+ {
5018+ int64_t active_handles = (int64_t )node_impl->thread_loop ->active_handles +
5019+ (int64_t )node_impl->thread_loop ->active_reqs .count +
5020+ node_loader_impl_async_closing_handles_count (node_impl);
50045021
50055022 return active_handles;
50065023}
@@ -5011,11 +5028,15 @@ int64_t node_loader_impl_user_async_handles_count(loader_impl_node node_impl)
50115028 int64_t extra_active_handles = node_impl->extra_active_handles .load ();
50125029
50135030#if (!defined(NDEBUG) || defined(DEBUG) || defined(_DEBUG) || defined(__DEBUG) || defined(__DEBUG__))
5014- printf (" [active_handles] - [base_active_handles] - [extra_active_handles]\n " );
5015- printf (" %" PRId64 " - %" PRId64 " - %" PRId64 " \n " ,
5016- active_handles,
5031+ int64_t closing = node_loader_impl_async_closing_handles_count (node_impl);
5032+
5033+ printf (" [active_handles] - [base_active_handles] - [extra_active_handles] + [active_reqs] + [closing]\n " );
5034+ printf (" %" PRId64 " - %" PRId64 " - %" PRId64 " + %" PRId64 " + %" PRId64 " \n " ,
5035+ (int64_t )node_impl->thread_loop ->active_handles ,
50175036 node_impl->base_active_handles ,
5018- extra_active_handles);
5037+ extra_active_handles,
5038+ (int64_t )node_impl->thread_loop ->active_reqs .count ,
5039+ closing);
50195040#endif
50205041
50215042 return active_handles - node_impl->base_active_handles - extra_active_handles;
0 commit comments