@@ -22,6 +22,7 @@ static const size_t kTraceIdSize = 32;
22
22
static const size_t kSpanIdSize = 16 ;
23
23
24
24
static std::atomic<bool > is_running_ = { false };
25
+ nsuv::ns_rwlock exit_lock_;
25
26
static resource::ResourceAttributes resource_attributes_;
26
27
27
28
namespace node {
@@ -203,7 +204,7 @@ int OTLPAgent::config(const nlohmann::json& config) {
203
204
/* static*/ void OTLPAgent::config_agent_cb_ (std::string config,
204
205
OTLPAgent* agent) {
205
206
// Check if the agent is already delete or if it's closing
206
- nsuv::ns_rwlock::scoped_rdlock lock (agent-> exit_lock_ );
207
+ nsuv::ns_rwlock::scoped_rdlock lock (exit_lock_);
207
208
if (!is_running_) {
208
209
return ;
209
210
}
@@ -217,6 +218,11 @@ int OTLPAgent::config(const nlohmann::json& config) {
217
218
218
219
219
220
/* static*/ void OTLPAgent::config_msg_cb_ (nsuv::ns_async*, OTLPAgent* agent) {
221
+ nsuv::ns_rwlock::scoped_rdlock lock (exit_lock_);
222
+ if (!is_running_) {
223
+ return ;
224
+ }
225
+
220
226
json config_msg;
221
227
while (agent->config_msg_q_ .dequeue (config_msg)) {
222
228
agent->config (config_msg);
@@ -225,7 +231,7 @@ int OTLPAgent::config(const nlohmann::json& config) {
225
231
226
232
227
233
/* static*/ void OTLPAgent::env_msg_cb_ (nsuv::ns_async*, OTLPAgent* agent) {
228
- nsuv::ns_rwlock::scoped_rdlock lock (agent-> exit_lock_ );
234
+ nsuv::ns_rwlock::scoped_rdlock lock (exit_lock_);
229
235
if (!is_running_) {
230
236
return ;
231
237
}
@@ -249,7 +255,7 @@ int OTLPAgent::config(const nlohmann::json& config) {
249
255
250
256
/* static*/ void OTLPAgent::on_thread_add_ (SharedEnvInst envinst,
251
257
OTLPAgent* agent) {
252
- nsuv::ns_rwlock::scoped_rdlock lock (agent-> exit_lock_ );
258
+ nsuv::ns_rwlock::scoped_rdlock lock (exit_lock_);
253
259
if (!is_running_) {
254
260
return ;
255
261
}
@@ -261,7 +267,7 @@ int OTLPAgent::config(const nlohmann::json& config) {
261
267
262
268
/* static*/ void OTLPAgent::on_thread_remove_ (SharedEnvInst envinst,
263
269
OTLPAgent* agent) {
264
- nsuv::ns_rwlock::scoped_rdlock lock (agent-> exit_lock_ );
270
+ nsuv::ns_rwlock::scoped_rdlock lock (exit_lock_);
265
271
if (!is_running_) {
266
272
return ;
267
273
}
@@ -309,7 +315,7 @@ void OTLPAgent::do_stop() {
309
315
void OTLPAgent::trace_hook_ (Tracer* tracer,
310
316
const Tracer::SpanStor& stor,
311
317
OTLPAgent* agent) {
312
- nsuv::ns_rwlock::scoped_rdlock lock (agent-> exit_lock_ );
318
+ nsuv::ns_rwlock::scoped_rdlock lock (exit_lock_);
313
319
if (!is_running_) {
314
320
return ;
315
321
}
@@ -321,7 +327,7 @@ void OTLPAgent::trace_hook_(Tracer* tracer,
321
327
322
328
void OTLPAgent::span_msg_cb_ (nsuv::ns_async*, OTLPAgent* agent) {
323
329
// Don't exit until all the pending spans are sent
324
- nsuv::ns_rwlock::scoped_rdlock lock (agent-> exit_lock_ );
330
+ nsuv::ns_rwlock::scoped_rdlock lock (exit_lock_);
325
331
if (!is_running_) {
326
332
return ;
327
333
}
@@ -396,7 +402,7 @@ void OTLPAgent::span_msg_cb_(nsuv::ns_async*, OTLPAgent* agent) {
396
402
397
403
398
404
/* static*/ void OTLPAgent::metrics_timer_cb_ (nsuv::ns_timer*, OTLPAgent* agent) {
399
- nsuv::ns_rwlock::scoped_rdlock lock (agent-> exit_lock_ );
405
+ nsuv::ns_rwlock::scoped_rdlock lock (exit_lock_);
400
406
if (!is_running_) {
401
407
return ;
402
408
}
@@ -411,7 +417,7 @@ void OTLPAgent::span_msg_cb_(nsuv::ns_async*, OTLPAgent* agent) {
411
417
412
418
413
419
/* static*/ void OTLPAgent::metrics_msg_cb_ (nsuv::ns_async*, OTLPAgent* agent) {
414
- nsuv::ns_rwlock::scoped_rdlock lock (agent-> exit_lock_ );
420
+ nsuv::ns_rwlock::scoped_rdlock lock (exit_lock_);
415
421
if (!is_running_) {
416
422
return ;
417
423
}
@@ -437,7 +443,7 @@ void OTLPAgent::span_msg_cb_(nsuv::ns_async*, OTLPAgent* agent) {
437
443
438
444
/* static*/ void OTLPAgent::thr_metrics_cb_ (ThreadMetrics* metrics,
439
445
OTLPAgent* agent) {
440
- nsuv::ns_rwlock::scoped_rdlock lock (agent-> exit_lock_ );
446
+ nsuv::ns_rwlock::scoped_rdlock lock (exit_lock_);
441
447
if (!is_running_) {
442
448
return ;
443
449
}
0 commit comments