mirror of https://github.com/OISF/suricata
threads: fix autofp shutdown race condition
Sometimes a single flow pcap would log 2 flows. It turns out FlowWorkToDoCleanup ran before all the packet threads had processed their "wire" packets. It then removed a flow that a wire packet would still have needed, leading to the worker thread creating a new flow for it. This could happen due to the logic in TmThreadDisableReceiveThreads which calls TmThreadDrainPacketThreads to made sure it only returns when all autofp-workers have processed all the packets the autofp-capture thread fed to them. However, the way it checked this is by checking the size of the autofp-worker's input queue. If 0, it assumes it is done. What this missed, is that a worker thread could have just taken the last packet from the input queue, but it is not yet done processing it. If then the FlowWorkToDoCleanup is ran as well, it would race the worker thread to the flow handling logic. When it won, the flow was evicted and the packet thread created a new flow. This patch improves the shutdown logic to force the worker threads to enter a "flow loop" (THV_FLOW_LOOP) state before moving on to the FlowWorkToDoCleanup step. This makes sure that any in progress packets in the worker threads have been processed. Bug: #7681.pull/13125/head
parent
b42eea67d5
commit
12f8f03532
Loading…
Reference in New Issue