@cryptotaxi247 / netdata-1 / commits / f0f0426dc

fix(go.d): unlock job files on quit/restart (#19153)

Ilya Mashchenko committed Dec 7, 2024 at 19:12 UTC f0f0426dc0006ee933a09829d8968b88a86fcfeb
5 files changed +10 -8
src/go/plugin/go.d/agent/filelock/filelock.go
+6
@@ -54,6 +54,12 @@ func (l *Locker) Unlock(name string) {
54 _ = locker.Close()
55 }
56
57 +func (l *Locker) UnlockAll() {
58 + for name := range l.locks {
59 + l.Unlock(name)
60 + }
61 +}
62 +
63 func (l *Locker) isLocked(name string) bool {
64 _, ok := l.locks[l.filename(name)]
65 return ok
src/go/plugin/go.d/agent/filestatus/manager.go
+1 -8
@@ -87,12 +87,5 @@ func (m *Manager) flush() {
87 if err != nil {
88 return
89 }
90 -
91 - f, err := os.Create(m.path)
92 - if err != nil {
93 - return
94 - }
95 - defer func() { _ = f.Close() }()
96 -
97 - _, _ = f.Write(bs)
90 + _ = os.WriteFile(m.path, bs, 0644)
91 }
src/go/plugin/go.d/agent/jobmgr/di.go
+1
@@ -12,6 +12,7 @@ import (
12 type FileLocker interface {
13 Lock(name string) (bool, error)
14 Unlock(name string)
15 + UnlockAll()
16 }
17
18 type FileStatus interface {
src/go/plugin/go.d/agent/jobmgr/manager.go
+1
@@ -257,6 +257,7 @@ func (m *Manager) stopRunningJob(name string) {
257 }
258
259 func (m *Manager) cleanup() {
260 + m.FileLock.UnlockAll()
261 m.FnReg.Unregister("config")
262
263 m.runningJobs.lock()
src/go/plugin/go.d/agent/jobmgr/noop.go
+1
@@ -13,6 +13,7 @@ type noop struct{}
13
14 func (n noop) Lock(string) (bool, error) { return true, nil }
15 func (n noop) Unlock(string) {}
16 +func (n noop) UnlockAll() {}
17 func (n noop) Save(confgroup.Config, string) {}
18 func (n noop) Remove(confgroup.Config) {}
19 func (n noop) Contains(confgroup.Config, ...string) bool { return false }