Skip to content

Commit a515d48

Browse files
addaleaxgibfahn
authored andcommitted
src: remove async_hooks destroy timer handle
PR-URL: nodejs#17117 Backport-PR-URL: nodejs#18179 Reviewed-By: James M Snell <[email protected]>
1 parent 7571550 commit a515d48

File tree

6 files changed

+14
-34
lines changed

6 files changed

+14
-34
lines changed

src/async_wrap.cc

+2-7
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,7 @@ RetainedObjectInfo* WrapperInfo(uint16_t class_id, Local<Value> wrapper) {
138138
// end RetainedAsyncInfo
139139

140140

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

148144
TryCatch try_catch(env->isolate());
@@ -690,8 +686,7 @@ void AsyncWrap::EmitDestroy(Environment* env, double async_id) {
690686
return;
691687

692688
if (env->destroy_async_id_list()->empty()) {
693-
uv_timer_start(env->destroy_async_ids_timer_handle(),
694-
DestroyAsyncIdsCallback, 0, 0);
689+
env->SetImmediate(DestroyAsyncIdsCallback, nullptr);
695690
}
696691

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

src/env-inl.h

-9
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,6 @@ inline uv_idle_t* Environment::immediate_idle_handle() {
388388
return &immediate_idle_handle_;
389389
}
390390

391-
inline Environment* Environment::from_destroy_async_ids_timer_handle(
392-
uv_timer_t* handle) {
393-
return ContainerOf(&Environment::destroy_async_ids_timer_handle_, handle);
394-
}
395-
396-
inline uv_timer_t* Environment::destroy_async_ids_timer_handle() {
397-
return &destroy_async_ids_timer_handle_;
398-
}
399-
400391
inline void Environment::RegisterHandleCleanup(uv_handle_t* handle,
401392
HandleCleanupCb cb,
402393
void *arg) {

src/env.cc

-6
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ void Environment::Start(int argc,
4242
uv_unref(reinterpret_cast<uv_handle_t*>(&idle_prepare_handle_));
4343
uv_unref(reinterpret_cast<uv_handle_t*>(&idle_check_handle_));
4444

45-
uv_timer_init(event_loop(), destroy_async_ids_timer_handle());
46-
4745
auto close_and_finish = [](Environment* env, uv_handle_t* handle, void* arg) {
4846
handle->data = env;
4947

@@ -68,10 +66,6 @@ void Environment::Start(int argc,
6866
reinterpret_cast<uv_handle_t*>(&idle_check_handle_),
6967
close_and_finish,
7068
nullptr);
71-
RegisterHandleCleanup(
72-
reinterpret_cast<uv_handle_t*>(&destroy_async_ids_timer_handle_),
73-
close_and_finish,
74-
nullptr);
7569

7670
if (start_profiler_idle_notifier) {
7771
StartProfilerIdleNotifier();

src/env.h

-4
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,8 @@ class Environment {
561561
inline uint32_t watched_providers() const;
562562

563563
static inline Environment* from_immediate_check_handle(uv_check_t* handle);
564-
static inline Environment* from_destroy_async_ids_timer_handle(
565-
uv_timer_t* handle);
566564
inline uv_check_t* immediate_check_handle();
567565
inline uv_idle_t* immediate_idle_handle();
568-
inline uv_timer_t* destroy_async_ids_timer_handle();
569566

570567
// Register clean-up cb to be called on environment destruction.
571568
inline void RegisterHandleCleanup(uv_handle_t* handle,
@@ -706,7 +703,6 @@ class Environment {
706703
IsolateData* const isolate_data_;
707704
uv_check_t immediate_check_handle_;
708705
uv_idle_t immediate_idle_handle_;
709-
uv_timer_t destroy_async_ids_timer_handle_;
710706
uv_prepare_t idle_prepare_handle_;
711707
uv_check_t idle_check_handle_;
712708

test/async-hooks/test-signalwrap.js

+8-6
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

+4-2
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)