fix: hold closedM for both ReportLog and ReportState in RunDaemon

After Close() sets r.closed, the daemon should make zero network calls.
Move ReportLog(false) under the same closedM guard as ReportState() so
the daemon skips both when closed. This also simplifies RunDaemon by
using a single lock/unlock pair.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
silverwind
2026-02-19 03:13:55 +01:00
co-authored by Claude Opus 4.6
parent a4a6e291d5
commit 39cef65b52
+5 -11
View File
@@ -178,26 +178,20 @@ func (r *Reporter) Fire(entry *log.Entry) error {
}
func (r *Reporter) RunDaemon() {
r.closedM.Lock()
if r.closed {
r.closedM.Unlock()
return
}
r.closedM.Unlock()
if r.ctx.Err() != nil {
return
}
_ = r.ReportLog(false)
r.closedM.Lock()
defer r.closedM.Unlock()
if !r.closed {
_ = r.ReportState()
if r.closed {
return
}
_ = r.ReportLog(false)
_ = r.ReportState()
time.AfterFunc(time.Second, r.RunDaemon)
}