Skip to content

Commit 8ab251f

Browse files
committed
Fix systemd.Apply() to check for DBus error before waiting on a channel.
The channel was introduced in #1683 to work around a race condition. However, the check for error in StartTransientUnit ignores the error for an already existing unit, and in that case there will be no notification from DBus (so waiting on the channel will make it hang.) Later PR #1754 added a timeout, which worked around the issue, but we can fix this correctly by only waiting on the channel when there is no error. Fix the code to do so. The timeout handling was kept, since there might be other cases where this situation occurs (https://bugzilla.redhat.com/show_bug.cgi?id=1548358 mentions calling this code from inside a container, it's unclear whether an existing container was in use or not, so not sure whether this would have fixed that bug as well.) Signed-off-by: Filipe Brandenburger <[email protected]>
1 parent cc4307a commit 8ab251f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

libcontainer/cgroups/systemd/apply_systemd.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,16 @@ func (m *Manager) Apply(pid int) error {
297297
}
298298

299299
statusChan := make(chan string)
300-
if _, err := theConn.StartTransientUnit(unitName, "replace", properties, statusChan); err != nil && !isUnitExists(err) {
300+
if _, err := theConn.StartTransientUnit(unitName, "replace", properties, statusChan); err == nil {
301+
select {
302+
case <-statusChan:
303+
case <-time.After(time.Second):
304+
logrus.Warnf("Timed out while waiting for StartTransientUnit(%s) completion signal from dbus. Continuing...", unitName)
305+
}
306+
} else if !isUnitExists(err) {
301307
return err
302308
}
303309

304-
select {
305-
case <-statusChan:
306-
case <-time.After(time.Second):
307-
logrus.Warnf("Timed out while waiting for StartTransientUnit completion signal from dbus. Continuing...")
308-
}
309-
310310
if err := joinCgroups(c, pid); err != nil {
311311
return err
312312
}

0 commit comments

Comments
 (0)