Skip to content

Commit 8436144

Browse files
loggers, remote_syslog: check if we're connected
when writing, check if we're connected, or reconnecting.
1 parent efc0566 commit 8436144

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

daemon/log/loggers/remote_syslog.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,22 @@ func (s *RemoteSyslog) Write(msg string) {
168168
// and have a continuous stream of events. Otherwise it'd stop working.
169169
// I haven't figured out yet why these write errors ocurr.
170170
s.mu.RLock()
171+
defer s.mu.RUnlock()
172+
if s.netConn == nil {
173+
s.ReOpen()
174+
return
175+
}
171176
s.netConn.SetWriteDeadline(deadline)
172177
_, err := s.netConn.Write([]byte(msg))
173-
s.mu.RUnlock()
178+
if err == nil {
179+
return
180+
}
174181

175-
if err != nil {
176-
log.Debug("[%s] %s write error: %v", s.Name, s.cfg.Protocol, err.(net.Error))
177-
atomic.AddUint32(&s.errors, 1)
178-
if atomic.LoadUint32(&s.errors) > maxAllowedErrors {
179-
s.ReOpen()
180-
return
181-
}
182+
log.Debug("[%s] %s write error: %v", s.Name, s.cfg.Protocol, err.(net.Error))
183+
atomic.AddUint32(&s.errors, 1)
184+
if atomic.LoadUint32(&s.errors) > maxAllowedErrors {
185+
s.ReOpen()
186+
return
182187
}
183188
}
184189

0 commit comments

Comments
 (0)