FDio / govpp

Go toolset for the VPP.
Apache License 2.0
185 stars 81 forks source link

Disconnect Stats panic #215

Open PFangwang opened 1 month ago

PFangwang commented 1 month ago

your func:

func (c *StatsConnection) Disconnect() {
    if c == nil {
        return
    }
    if c.statsClient != nil {
        if err := c.statsClient.Disconnect(); err != nil {
            log.Debugf("disconnecting stats client failed: %v", err)
        }
    }
    close(c.connChan)
    close(c.done)
}

in another fiber:

case <-c.done:
    log.Debugf("health check watcher closed")
    c.sendStatsConnEvent(ConnectionEvent{Timestamp: time.Now(), State: Disconnected, Error: nil})
    return
}

func sendStatsConnEvent:

func (c *StatsConnection) sendStatsConnEvent(event ConnectionEvent) {
    select {
    case c.connChan <- event:
    default:
        log.Warn("Stats connection state channel is full, discarding value.")
    }
}

note this: case c.connChan <- event: now the c.connChan is cloed,then panic