flow/manager: fix threading/locking coverity warnings

In flow manager and recycler timed condition wait loops.

First check loop break conditions before entiring the timed wait.

CID 1638284: (#1 of 1): Indefinite wait (BAD_CHECK_OF_WAIT_COND)
dead_wait: A wait is performed without ensuring that the condition is not already satisfied while holding lock flow_manager_ctrl_mutex. This can cause a deadlock if the notification happens before the lock is acquired.

CID 1638293: (#1 of 1): Indefinite wait (BAD_CHECK_OF_WAIT_COND)
dead_wait: A wait is performed without ensuring that the condition is not already satisfied while holding lock flow_recycler_ctrl_mutex. This can cause a deadlock if the notification happens before the lock is acquired.
pull/13518/head
Victor Julien 5 months ago committed by Victor Julien
parent f332b3e571
commit 5aaef39c8c

@ -977,11 +977,12 @@ static TmEcode FlowManager(ThreadVars *th_v, void *thread_data)
struct timespec cond_time = FROM_TIMEVAL(cond_tv);
SCCtrlMutexLock(&flow_manager_ctrl_mutex);
while (1) {
if (SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY) {
break;
}
int rc = SCCtrlCondTimedwait(
&flow_manager_ctrl_cond, &flow_manager_ctrl_mutex, &cond_time);
if (rc == ETIMEDOUT || rc < 0)
break;
if (SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY) {
if (rc == ETIMEDOUT || rc < 0) {
break;
}
}
@ -1153,17 +1154,17 @@ static TmEcode FlowRecycler(ThreadVars *th_v, void *thread_data)
struct timespec cond_time = FROM_TIMEVAL(cond_tv);
SCCtrlMutexLock(&flow_recycler_ctrl_mutex);
while (1) {
int rc = SCCtrlCondTimedwait(
&flow_recycler_ctrl_cond, &flow_recycler_ctrl_mutex, &cond_time);
if (rc == ETIMEDOUT || rc < 0) {
break;
}
if (SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY) {
break;
}
if (SC_ATOMIC_GET(flow_recycle_q.non_empty)) {
break;
}
int rc = SCCtrlCondTimedwait(
&flow_recycler_ctrl_cond, &flow_recycler_ctrl_mutex, &cond_time);
if (rc == ETIMEDOUT || rc < 0) {
break;
}
}
SCCtrlMutexUnlock(&flow_recycler_ctrl_mutex);
}

Loading…
Cancel
Save