Skip to content

Commit 96651b0

Browse files
committed
Trying to solve more bugs from node loader event loop.
1 parent 84df336 commit 96651b0

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

source/loaders/node_loader/source/node_loader_impl.cpp

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

tools/metacall-environment.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,13 +488,14 @@ sub_nodejs(){
488488
$SUDO_CMD apk del .build-nodejs-python-deps
489489
fi
490490
elif [ "${OPERATIVE_SYSTEM}" = "Darwin" ]; then
491-
brew install node@16 make curl
491+
# TODO: Fork backend-nodejs or let metacall build system compile NodeJS library itself
492+
brew install node@16
492493
# Make node 16 the default
493494
brew link node@16 --force --overwrite
494495
NODE_PREFIX=$(brew --prefix node@16)
495496
wget https://github.com/puerts/backend-nodejs/releases/download/NodeJS_16.16.0_230216/nodejs_bin_16.16.0.tgz
496497
tar -xzf nodejs_bin_16.16.0.tgz
497-
# copy dylib to /usr/local/lib
498+
# Copy dylib to /usr/local/lib
498499
sudo cp nodejs_16/lib/macOS/libnode.93.dylib $NODE_PREFIX/lib
499500
mkdir -p build
500501
CMAKE_CONFIG_PATH="$ROOT_DIR/build/CMakeConfig.txt"

0 commit comments

Comments
 (0)