Skip to content

Commit

Permalink
Remove service from systemd watch filter when dbus remove event is re…
Browse files Browse the repository at this point in the history
…ceived to avoid potential race condition between file system event and dbus event
  • Loading branch information
jordigilh committed Aug 4, 2022
1 parent 0dc1118 commit 362dcd5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions internal/service/event_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ func (e *DBusEventListener) Listen() {
case running:
log.Debugf("Sending start event to observer channel for workload %s", n)
e.observerCh <- &Event{WorkloadName: n, Type: EventStarted}
case removed, stop, dead, failed, start:
case removed:
// 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.
log.Infof("Service %s disabled or removed", name)
e.Remove(name)
fallthrough
case stop, dead, failed, start:
log.Debugf("Sending stop event to observer channel for workload %s", n)
e.observerCh <- &Event{WorkloadName: n, Type: EventStopped}
default:
Expand Down Expand Up @@ -165,11 +170,10 @@ func (e *DBusEventListener) watchFSEvents() {
svcName := getServiceFileName(event.Name)
switch {
case event.Op&fsnotify.Create == fsnotify.Create:
log.Infof("New service configuration detected at %s", event.Name)
log.Infof("New systemd service unit file %s detected", event.Name)
e.Add(svcName)
case event.Op&fsnotify.Remove == fsnotify.Remove:
log.Infof("Service configuration removed at %s", event.Name)
e.Remove(svcName)
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)
}
case err, ok := <-e.fsWatcher.Errors:
if !ok {
Expand Down

0 comments on commit 362dcd5

Please sign in to comment.