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

src: add debug check for inspector uv_async_t #25777

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
9 changes: 9 additions & 0 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ using v8_inspector::V8InspectorClient;

static uv_sem_t start_io_thread_semaphore;
static uv_async_t start_io_thread_async;
// This is just an additional check to make sure start_io_thread_async
// is not accidentally re-used or used when uninitialized.
static std::atomic_bool start_io_thread_async_initialized { false };

class StartIoTask : public Task {
public:
Expand Down Expand Up @@ -88,6 +91,7 @@ static void StartIoThreadWakeup(int signo) {
inline void* StartIoThreadMain(void* unused) {
for (;;) {
uv_sem_wait(&start_io_thread_semaphore);
CHECK(start_io_thread_async_initialized);
Agent* agent = static_cast<Agent*>(start_io_thread_async.data);
if (agent != nullptr)
agent->RequestIoThreadStart();
Expand Down Expand Up @@ -141,6 +145,7 @@ static int StartDebugSignalHandler() {

#ifdef _WIN32
DWORD WINAPI StartIoThreadProc(void* arg) {
CHECK(start_io_thread_async_initialized);
Agent* agent = static_cast<Agent*>(start_io_thread_async.data);
if (agent != nullptr)
agent->RequestIoThreadStart();
Expand Down Expand Up @@ -660,6 +665,7 @@ Agent::Agent(Environment* env)

Agent::~Agent() {
if (start_io_thread_async.data == this) {
CHECK(start_io_thread_async_initialized.exchange(false));
start_io_thread_async.data = nullptr;
// This is global, will never get freed
uv_close(reinterpret_cast<uv_handle_t*>(&start_io_thread_async), nullptr);
Expand All @@ -677,6 +683,7 @@ bool Agent::Start(const std::string& path,

client_ = std::make_shared<NodeInspectorClient>(parent_env_, is_main);
if (parent_env_->is_main_thread()) {
CHECK_EQ(start_io_thread_async_initialized.exchange(true), false);
CHECK_EQ(0, uv_async_init(parent_env_->event_loop(),
&start_io_thread_async,
StartIoThreadAsyncCallback));
Expand Down Expand Up @@ -843,13 +850,15 @@ void Agent::RequestIoThreadStart() {
// We need to attempt to interrupt V8 flow (in case Node is running
// continuous JS code) and to wake up libuv thread (in case Node is waiting
// for IO events)
CHECK(start_io_thread_async_initialized);
uv_async_send(&start_io_thread_async);
Isolate* isolate = parent_env_->isolate();
v8::Platform* platform = parent_env_->isolate_data()->platform();
std::shared_ptr<TaskRunner> taskrunner =
platform->GetForegroundTaskRunner(isolate);
taskrunner->PostTask(std::make_unique<StartIoTask>(this));
isolate->RequestInterrupt(StartIoInterrupt, this);
CHECK(start_io_thread_async_initialized);
uv_async_send(&start_io_thread_async);
}

Expand Down