@@ -533,6 +533,10 @@ static void node_loader_impl_thread_log(void *data);
533533
534534/* static void node_loader_impl_walk(uv_handle_t *handle, void *data); */
535535
536+ #if (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__)
537+ static void node_loader_impl_walk_async_handles_count (uv_handle_t *handle, void *arg);
538+ #endif
539+
536540static int64_t node_loader_impl_async_handles_count (loader_impl_node node_impl);
537541
538542static void node_loader_impl_try_destroy (loader_impl_node node_impl);
@@ -4992,6 +4996,7 @@ void node_loader_impl_destroy_safe(napi_env env, loader_impl_async_destroy_safe
49924996 node_loader_impl_exception (env, status);
49934997}
49944998
4999+ #if !defined(WIN32) || defined(_WIN32)
49955000struct node_loader_impl_uv__queue
49965001{
49975002 struct node_loader_impl_uv__queue *next;
@@ -5002,6 +5007,26 @@ static inline int uv__queue_empty(const struct node_loader_impl_uv__queue *q)
50025007{
50035008 return q == q->next ;
50045009}
5010+ #endif
5011+
5012+ #if (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__)
5013+ void node_loader_impl_walk_async_handles_count (uv_handle_t *handle, void *arg)
5014+ {
5015+ int64_t *async_count = static_cast <int64_t *>(arg);
5016+
5017+ if (uv_is_active (handle) && !uv_is_closing (handle))
5018+ {
5019+ // NOTE: I am not sure if this check for timers is correct, at least for versions
5020+ // previous from v11.0.0. Now the node loader seems to be working for versions >=v12.
5021+ // If there is any other error when closing, improve counter for timers and timeouts.
5022+ // Signals have been added because they do not prevent the event loop from closing.
5023+ if (/* (!(handle->type == UV_TIMER && !uv_has_ref(handle))) ||*/ handle->type != UV_SIGNAL)
5024+ {
5025+ (*async_count)++;
5026+ }
5027+ }
5028+ }
5029+ #endif
50055030
50065031int64_t node_loader_impl_async_closing_handles_count (loader_impl_node node_impl)
50075032{
@@ -5024,11 +5049,19 @@ int64_t node_loader_impl_async_closing_handles_count(loader_impl_node node_impl)
50245049
50255050int64_t node_loader_impl_async_handles_count (loader_impl_node node_impl)
50265051{
5052+ #if (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__)
5053+ int64_t active_handles = 0 ;
5054+ uv_walk (node_impl->thread_loop , node_loader_impl_walk_async_handles_count, (void *)&active_handles);
5055+
5056+ return active_handles +
5057+ (int64_t )(node_impl->thread_loop ->active_reqs .count > 0 ) +
5058+ node_loader_impl_async_closing_handles_count (node_impl);
5059+ #else
50275060 int64_t active_handles = (int64_t )node_impl->thread_loop ->active_handles +
50285061 (int64_t )(node_impl->thread_loop ->active_reqs .count > 0 ) +
50295062 node_loader_impl_async_closing_handles_count (node_impl);
5030-
50315063 return active_handles;
5064+ #endif
50325065}
50335066
50345067int64_t node_loader_impl_user_async_handles_count (loader_impl_node node_impl)
0 commit comments