@@ -51,6 +51,9 @@ using v8_inspector::V8InspectorClient;
51
51
52
52
static uv_sem_t start_io_thread_semaphore;
53
53
static uv_async_t start_io_thread_async;
54
+ // This is just an additional check to make sure start_io_thread_async
55
+ // is not accidentally re-used or used when uninitialized.
56
+ static std::atomic_bool start_io_thread_async_initialized { false };
54
57
55
58
class StartIoTask : public Task {
56
59
public:
@@ -88,6 +91,7 @@ static void StartIoThreadWakeup(int signo) {
88
91
inline void * StartIoThreadMain (void * unused) {
89
92
for (;;) {
90
93
uv_sem_wait (&start_io_thread_semaphore);
94
+ CHECK (start_io_thread_async_initialized);
91
95
Agent* agent = static_cast <Agent*>(start_io_thread_async.data );
92
96
if (agent != nullptr )
93
97
agent->RequestIoThreadStart ();
@@ -141,6 +145,7 @@ static int StartDebugSignalHandler() {
141
145
142
146
#ifdef _WIN32
143
147
DWORD WINAPI StartIoThreadProc (void * arg) {
148
+ CHECK (start_io_thread_async_initialized);
144
149
Agent* agent = static_cast <Agent*>(start_io_thread_async.data );
145
150
if (agent != nullptr )
146
151
agent->RequestIoThreadStart ();
@@ -664,6 +669,7 @@ Agent::Agent(Environment* env)
664
669
665
670
Agent::~Agent () {
666
671
if (start_io_thread_async.data == this ) {
672
+ CHECK (start_io_thread_async_initialized.exchange (false ));
667
673
start_io_thread_async.data = nullptr ;
668
674
// This is global, will never get freed
669
675
uv_close (reinterpret_cast <uv_handle_t *>(&start_io_thread_async), nullptr );
@@ -681,6 +687,7 @@ bool Agent::Start(const std::string& path,
681
687
682
688
client_ = std::make_shared<NodeInspectorClient>(parent_env_, is_main);
683
689
if (parent_env_->is_main_thread ()) {
690
+ CHECK_EQ (start_io_thread_async_initialized.exchange (true ), false );
684
691
CHECK_EQ (0 , uv_async_init (parent_env_->event_loop (),
685
692
&start_io_thread_async,
686
693
StartIoThreadAsyncCallback));
@@ -847,13 +854,15 @@ void Agent::RequestIoThreadStart() {
847
854
// We need to attempt to interrupt V8 flow (in case Node is running
848
855
// continuous JS code) and to wake up libuv thread (in case Node is waiting
849
856
// for IO events)
857
+ CHECK (start_io_thread_async_initialized);
850
858
uv_async_send (&start_io_thread_async);
851
859
Isolate* isolate = parent_env_->isolate ();
852
860
v8::Platform* platform = parent_env_->isolate_data ()->platform ();
853
861
std::shared_ptr<TaskRunner> taskrunner =
854
862
platform->GetForegroundTaskRunner (isolate);
855
863
taskrunner->PostTask (std::make_unique<StartIoTask>(this ));
856
864
isolate->RequestInterrupt (StartIoInterrupt, this );
865
+ CHECK (start_io_thread_async_initialized);
857
866
uv_async_send (&start_io_thread_async);
858
867
}
859
868
0 commit comments