Skip to content
Prev Previous commit
Next Next commit
Fix retry behavior
  • Loading branch information
srebhan committed Jun 11, 2024
commit 427e6ab1108cd5078fa2e7298c0a9b1c654d8dae
4 changes: 4 additions & 0 deletions plugins/inputs/mqtt_consumer/mqtt_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func (m *MQTTConsumer) connect() error {
// Network errors might be retryable, stop the metric-tracking
// goroutine and return a retryable error.
m.cancel()
m.cancel = nil
return &internal.StartupError{
Err: token.Error(),
Retry: true,
Expand Down Expand Up @@ -327,6 +328,9 @@ func (m *MQTTConsumer) Stop() {
}
func (m *MQTTConsumer) Gather(_ telegraf.Accumulator) error {
if !m.client.IsConnected() {
if m.cancel == nil {
return internal.ErrNotConnected
}
m.Log.Debugf("Connecting %v", m.Servers)
return m.connect()
}
Expand Down