cloudflare / goflow

The high-scalability sFlow/NetFlow/IPFIX collector used internally at Cloudflare.
BSD 3-Clause "New" or "Revised" License
859 stars 172 forks source link

Issue in NetFlow processor stop logic #40

Closed raghurampai closed 4 years ago

raghurampai commented 5 years ago

Noticed an issue in NetFlow decoder's stop logic which can result in-
fatal error: all goroutines are asleep - deadlock!

Below is the issue described in decoders/decoder.go code-

func (w Worker) Start() {   
    go func() {  
        //log.Debugf("Worker %v started", w.Id)  
        for {  
            // w.WorkerPool <- w.InMsg  -- Issue commented  
            select {  
            case <-w.Quit:  
                break  
            // case msg := <-w.InMsg:  -- Issue commented  
            case w.WorkerPool <- w.InMsg:  // -- Fix added  
                    msg := <-w.InMsg    // -- Fix added  
                                timeTrackStart := time.Now()  

Go playground for quick check-
https://play.golang.org/p/LnDFz8vT_4G

Thanks!

lspgn commented 4 years ago

Thanks @raghurampai for the report. Made a PR for the fix. Will test.