diff options
author | Andrew Moss <1043609+amoss@users.noreply.github.com> | 2020-06-23 18:06:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-23 18:06:09 +0200 |
commit | 641a45923789b738a3c75183b5b44b6d26964c86 (patch) | |
tree | 3206f03d0d1148e19ec83f8dd5937e8f863821e0 /database | |
parent | 93704281a5ae215f031c7c7c6b2c3706e9d097ca (diff) |
Fix Coverity Defect CID 304732 (#9402)
Fix a race-hazard in the shutdown sequence that could deadlock the agent.
Diffstat (limited to 'database')
-rw-r--r-- | database/rrdhost.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/database/rrdhost.c b/database/rrdhost.c index d349830730..c61ae561d5 100644 --- a/database/rrdhost.c +++ b/database/rrdhost.c @@ -686,11 +686,16 @@ void rrdhost_free(RRDHOST *host) { if (host->receiver) { if (!host->receiver->exited) netdata_thread_cancel(host->receiver->thread); - while (!host->receiver->exited) + netdata_mutex_unlock(&host->receiver_lock); + struct receiver_state *rpt = host->receiver; + while (host->receiver && !rpt->exited) sleep_usec(50 * USEC_PER_MS); - destroy_receiver_state(host->receiver); + // If the receiver detached from the host then its thread will destroy the state + if (host->receiver == rpt) + destroy_receiver_state(host->receiver); } - netdata_mutex_unlock(&host->receiver_lock); + else + netdata_mutex_unlock(&host->receiver_lock); } |