Skip to content

Commit

Permalink
loggers, remote_syslog: check if we're connected
Browse files Browse the repository at this point in the history
when writing, check if we're connected, or reconnecting.
  • Loading branch information
gustavo-iniguez-goya committed May 14, 2024
1 parent efc0566 commit 8436144
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions daemon/log/loggers/remote_syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,22 @@ func (s *RemoteSyslog) Write(msg string) {
// and have a continuous stream of events. Otherwise it'd stop working.
// I haven't figured out yet why these write errors ocurr.
s.mu.RLock()
defer s.mu.RUnlock()
if s.netConn == nil {
s.ReOpen()
return
}
s.netConn.SetWriteDeadline(deadline)
_, err := s.netConn.Write([]byte(msg))
s.mu.RUnlock()
if err == nil {
return
}

if err != nil {
log.Debug("[%s] %s write error: %v", s.Name, s.cfg.Protocol, err.(net.Error))
atomic.AddUint32(&s.errors, 1)
if atomic.LoadUint32(&s.errors) > maxAllowedErrors {
s.ReOpen()
return
}
log.Debug("[%s] %s write error: %v", s.Name, s.cfg.Protocol, err.(net.Error))
atomic.AddUint32(&s.errors, 1)
if atomic.LoadUint32(&s.errors) > maxAllowedErrors {
s.ReOpen()
return
}
}

Expand Down

0 comments on commit 8436144

Please sign in to comment.