Skip to content

Commit 5d7f5c1

Browse files
committed
src: remove async_hooks destroy timer handle
PR-URL: #17117 Reviewed-By: James M Snell <[email protected]>
1 parent 85f3e31 commit 5d7f5c1

File tree

6 files changed

+14
-34
lines changed

6 files changed

+14
-34
lines changed

src/async_wrap.cc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,7 @@ RetainedObjectInfo* WrapperInfo(uint16_t class_id, Local<Value> wrapper) {
137137
// end RetainedAsyncInfo
138138

139139

140-
static void DestroyAsyncIdsCallback(uv_timer_t* handle) {
141-
Environment* env = Environment::from_destroy_async_ids_timer_handle(handle);
142-
143-
HandleScope handle_scope(env->isolate());
144-
Context::Scope context_scope(env->context());
140+
static void DestroyAsyncIdsCallback(Environment* env, void* data) {
145141
Local<Function> fn = env->async_hooks_destroy_function();
146142

147143
TryCatch try_catch(env->isolate());
@@ -689,8 +685,7 @@ void AsyncWrap::EmitDestroy(Environment* env, double async_id) {
689685
return;
690686

691687
if (env->destroy_async_id_list()->empty()) {
692-
uv_timer_start(env->destroy_async_ids_timer_handle(),
693-
DestroyAsyncIdsCallback, 0, 0);
688+
env->SetImmediate(DestroyAsyncIdsCallback, nullptr);
694689
}
695690

696691
env->destroy_async_id_list()->push_back(async_id);

src/env-inl.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -345,15 +345,6 @@ inline uv_idle_t* Environment::immediate_idle_handle() {
345345
return &immediate_idle_handle_;
346346
}
347347

348-
inline Environment* Environment::from_destroy_async_ids_timer_handle(
349-
uv_timer_t* handle) {
350-
return ContainerOf(&Environment::destroy_async_ids_timer_handle_, handle);
351-
}
352-
353-
inline uv_timer_t* Environment::destroy_async_ids_timer_handle() {
354-
return &destroy_async_ids_timer_handle_;
355-
}
356-
357348
inline void Environment::RegisterHandleCleanup(uv_handle_t* handle,
358349
HandleCleanupCb cb,
359350
void *arg) {

src/env.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ void Environment::Start(int argc,
9696
uv_unref(reinterpret_cast<uv_handle_t*>(&idle_prepare_handle_));
9797
uv_unref(reinterpret_cast<uv_handle_t*>(&idle_check_handle_));
9898

99-
uv_timer_init(event_loop(), destroy_async_ids_timer_handle());
100-
10199
auto close_and_finish = [](Environment* env, uv_handle_t* handle, void* arg) {
102100
handle->data = env;
103101

@@ -122,10 +120,6 @@ void Environment::Start(int argc,
122120
reinterpret_cast<uv_handle_t*>(&idle_check_handle_),
123121
close_and_finish,
124122
nullptr);
125-
RegisterHandleCleanup(
126-
reinterpret_cast<uv_handle_t*>(&destroy_async_ids_timer_handle_),
127-
close_and_finish,
128-
nullptr);
129123

130124
if (start_profiler_idle_notifier) {
131125
StartProfilerIdleNotifier();

src/env.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,8 @@ class Environment {
544544
inline uint32_t watched_providers() const;
545545

546546
static inline Environment* from_immediate_check_handle(uv_check_t* handle);
547-
static inline Environment* from_destroy_async_ids_timer_handle(
548-
uv_timer_t* handle);
549547
inline uv_check_t* immediate_check_handle();
550548
inline uv_idle_t* immediate_idle_handle();
551-
inline uv_timer_t* destroy_async_ids_timer_handle();
552549

553550
// Register clean-up cb to be called on environment destruction.
554551
inline void RegisterHandleCleanup(uv_handle_t* handle,
@@ -701,7 +698,6 @@ class Environment {
701698
IsolateData* const isolate_data_;
702699
uv_check_t immediate_check_handle_;
703700
uv_idle_t immediate_idle_handle_;
704-
uv_timer_t destroy_async_ids_timer_handle_;
705701
uv_prepare_t idle_prepare_handle_;
706702
uv_check_t idle_check_handle_;
707703

test/async-hooks/test-signalwrap.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ function onsigusr2() {
6666
}
6767

6868
function onsigusr2Again() {
69-
checkInvocations(
70-
signal1, { init: 1, before: 2, after: 2, destroy: 1 },
71-
'signal1: when second SIGUSR2 handler is called');
72-
checkInvocations(
73-
signal2, { init: 1, before: 1 },
74-
'signal2: when second SIGUSR2 handler is called');
69+
setImmediate(() => {
70+
checkInvocations(
71+
signal1, { init: 1, before: 2, after: 2, destroy: 1 },
72+
'signal1: when second SIGUSR2 handler is called');
73+
checkInvocations(
74+
signal2, { init: 1, before: 1 },
75+
'signal2: when second SIGUSR2 handler is called');
76+
});
7577
}
7678

7779
process.on('exit', onexit);

test/async-hooks/test-tcpwrap.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ function onconnection(c) {
128128
function onserverClosed() {
129129
checkInvocations(tcp1, { init: 1, before: 1, after: 1, destroy: 1 },
130130
'tcp1 when server is closed');
131-
checkInvocations(tcp2, { init: 1, before: 2, after: 2, destroy: 1 },
132-
'tcp2 when server is closed');
131+
setImmediate(() => {
132+
checkInvocations(tcp2, { init: 1, before: 2, after: 2, destroy: 1 },
133+
'tcp2 after server is closed');
134+
});
133135
checkInvocations(tcp3, { init: 1, before: 1, after: 1 },
134136
'tcp3 synchronously when server is closed');
135137
tick(2, () => {

0 commit comments

Comments
 (0)