Skip to content
This repository was archived by the owner on Dec 1, 2024. It is now read-only.

Commit bb407e0

Browse files
committed
Remove service from systemd watch filter when dbus remove event is received to avoid potential race condition between file system event and dbus event
1 parent 9968393 commit bb407e0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

internal/service/event_listener.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,12 @@ func (e *DBusEventListener) Listen() {
136136
case running:
137137
log.Debugf("Sending start event to observer channel for workload %s", n)
138138
e.observerCh <- &Event{WorkloadName: n, Type: EventStarted}
139-
case removed, stop, dead, failed, start:
139+
case removed:
140+
// We remove the service from the filter here to avoid a potential race condition where the fs notify routine removes it before the systemd event is received.
141+
log.Infof("Service %s disabled or removed", name)
142+
e.Remove(name)
143+
fallthrough
144+
case stop, dead, failed, start:
140145
log.Debugf("Sending stop event to observer channel for workload %s", n)
141146
e.observerCh <- &Event{WorkloadName: n, Type: EventStopped}
142147
default:
@@ -165,11 +170,10 @@ func (e *DBusEventListener) watchFSEvents() {
165170
svcName := getServiceFileName(event.Name)
166171
switch {
167172
case event.Op&fsnotify.Create == fsnotify.Create:
168-
log.Infof("New service configuration detected at %s", event.Name)
173+
log.Infof("New systemd service unit file %s detected", event.Name)
169174
e.Add(svcName)
170175
case event.Op&fsnotify.Remove == fsnotify.Remove:
171-
log.Infof("Service configuration removed at %s", event.Name)
172-
e.Remove(svcName)
176+
log.Debugf("Systemd service unit file %s has been removed. Waiting for the systemd dbus remove event to elimitate it from the service watch filter", event.Name)
173177
}
174178
case err, ok := <-e.fsWatcher.Errors:
175179
if !ok {

0 commit comments

Comments
 (0)