@@ -398,7 +398,11 @@ void Environment::RegisterHandleCleanups() {
398
398
void * arg) {
399
399
handle->data = env;
400
400
401
- env->CloseHandle (handle, [](uv_handle_t * handle) {});
401
+ env->CloseHandle (handle, [](uv_handle_t * handle) {
402
+ #ifdef DEBUG
403
+ memset (handle, 0xab , uv_handle_size (handle->type ));
404
+ #endif
405
+ });
402
406
};
403
407
404
408
RegisterHandleCleanup (
@@ -512,6 +516,7 @@ void Environment::PrintSyncTrace() const {
512
516
}
513
517
514
518
void Environment::RunCleanup () {
519
+ started_cleanup_ = true ;
515
520
TraceEventScope trace_scope (TRACING_CATEGORY_NODE1 (environment),
516
521
" RunCleanup" , this );
517
522
CleanupHandles ();
@@ -660,10 +665,13 @@ void Environment::RunAndClearNativeImmediates() {
660
665
661
666
662
667
void Environment::ScheduleTimer (int64_t duration_ms) {
668
+ if (started_cleanup_) return ;
663
669
uv_timer_start (timer_handle (), RunTimers, duration_ms, 0 );
664
670
}
665
671
666
672
void Environment::ToggleTimerRef (bool ref) {
673
+ if (started_cleanup_) return ;
674
+
667
675
if (ref) {
668
676
uv_ref (reinterpret_cast <uv_handle_t *>(timer_handle ()));
669
677
} else {
@@ -763,6 +771,8 @@ void Environment::CheckImmediate(uv_check_t* handle) {
763
771
}
764
772
765
773
void Environment::ToggleImmediateRef (bool ref) {
774
+ if (started_cleanup_) return ;
775
+
766
776
if (ref) {
767
777
// Idle handle is needed only to stop the event loop from blocking in poll.
768
778
uv_idle_start (immediate_idle_handle (), [](uv_idle_t *){ });
0 commit comments