Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async_wrap: close the destroy_ids_idle_handle_ on environment destruction #10385

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,19 @@ inline Environment::Environment(IsolateData* isolate_data,
inline Environment::~Environment() {
v8::HandleScope handle_scope(isolate());

while (HandleCleanup* hc = handle_cleanup_queue_.PopFront()) {
handle_cleanup_waiting_++;
hc->cb_(this, hc->handle_, hc->arg_);
delete hc;
}

while (handle_cleanup_waiting_ != 0)
#define HANDLE_CLEANUP(queue) \
while (HandleCleanup* hc = queue.PopFront()) { \
handle_cleanup_waiting_++; \
hc->cb_(this, hc->handle_, hc->arg_); \
delete hc; \
} \
while (handle_cleanup_waiting_ != 0) \
uv_run(event_loop(), UV_RUN_ONCE);

HANDLE_CLEANUP(handle_cleanup_queue_);
HANDLE_CLEANUP(handle_cleanup_queue_delayed_);
#undef HANDLE_CLEANUP

context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex,
nullptr);
#define V(PropertyName, TypeName) PropertyName ## _.Reset();
Expand Down Expand Up @@ -264,6 +268,12 @@ inline void Environment::RegisterHandleCleanup(uv_handle_t* handle,
handle_cleanup_queue_.PushBack(new HandleCleanup(handle, cb, arg));
}

inline void Environment::RegisterHandleCleanupDelayed(uv_handle_t* handle,
HandleCleanupCb cb,
void *arg) {
handle_cleanup_queue_delayed_.PushBack(new HandleCleanup(handle, cb, arg));
}

inline void Environment::FinishHandleCleanup(uv_handle_t* handle) {
handle_cleanup_waiting_--;
}
Expand Down
6 changes: 6 additions & 0 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ void Environment::Start(int argc,
reinterpret_cast<uv_handle_t*>(&idle_check_handle_),
close_and_finish,
nullptr);
// The destroy ids idle handle has to be closed after all other
// handles have been closed for the destroy hook callback to be called.
RegisterHandleCleanupDelayed(
reinterpret_cast<uv_handle_t*>(destroy_ids_idle_handle()),
close_and_finish,
nullptr);

if (start_profiler_idle_notifier) {
StartProfilerIdleNotifier();
Expand Down
7 changes: 7 additions & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,11 @@ class Environment {
inline void RegisterHandleCleanup(uv_handle_t* handle,
HandleCleanupCb cb,
void *arg);
// Register clean-up cb to be called after all regular clean-up
// callbacks have been called.
inline void RegisterHandleCleanupDelayed(uv_handle_t* handle,
HandleCleanupCb cb,
void *arg);
inline void FinishHandleCleanup(uv_handle_t* handle);

inline AsyncHooks* async_hooks();
Expand Down Expand Up @@ -579,6 +584,8 @@ class Environment {
ReqWrapQueue req_wrap_queue_;
ListHead<HandleCleanup,
&HandleCleanup::handle_cleanup_queue_> handle_cleanup_queue_;
ListHead<HandleCleanup,
&HandleCleanup::handle_cleanup_queue_> handle_cleanup_queue_delayed_;
int handle_cleanup_waiting_;

double* heap_statistics_buffer_ = nullptr;
Expand Down