Skip to content

Commit

Permalink
Add max retries on resubscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
lisguo committed Jul 24, 2024
1 parent 6fd94b2 commit c20af64
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions plugins/inputs/windows_event_log/wineventlog/wineventlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ import (
const (
RPC_S_INVALID_BOUND syscall.Errno = 1734

collectionInterval = time.Second
saveStateInterval = 100 * time.Millisecond
collectionInterval = time.Second
saveStateInterval = 100 * time.Millisecond
subscribeMaxRetries = 3

apiEvtSubscribe = "EvtSubscribe"
apiEvtClose = "EvtClose"
Expand Down Expand Up @@ -132,6 +133,7 @@ func (w *windowsEventLog) run() {
ticker := time.NewTicker(collectionInterval)
defer ticker.Stop()

retryCount := 0
var shouldResubscribe bool
for {
select {
Expand All @@ -142,6 +144,12 @@ func (w *windowsEventLog) run() {
w.eventOffset = w.loadState()
if err := w.resubscribe(); err != nil {
log.Printf("E! [wineventlog] Unable to re-subscribe: %v", err)
retryCount++
if retryCount >= subscribeMaxRetries {
log.Printf("D! [wineventlog] Max subscribe retries reached: %d", subscribeMaxRetries)
shouldResubscribe = false
retryCount = 0
}
} else {
log.Printf("D! [wineventlog] Re-subscribed to %s", w.name)
shouldResubscribe = false
Expand Down

0 comments on commit c20af64

Please sign in to comment.