Skip to content

Commit 48d44d3

Browse files
author
“dsxing”
committed
context with timeout
1 parent a0466dd commit 48d44d3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

libcontainer/cgroups/systemd/common.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,10 @@ func startUnit(cm *dbusConnManager, unitName string, properties []systemdDbus.Pr
129129
retry := true
130130

131131
retry:
132+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
133+
defer cancel()
132134
err := cm.retryOnDisconnect(func(c *systemdDbus.Conn) error {
133-
_, err := c.StartTransientUnitContext(context.TODO(), unitName, "replace", properties, statusChan)
135+
_, err := c.StartTransientUnitContext(ctx, unitName, "replace", properties, statusChan)
134136
return err
135137
})
136138
if err != nil {
@@ -178,8 +180,10 @@ retry:
178180

179181
func stopUnit(cm *dbusConnManager, unitName string) error {
180182
statusChan := make(chan string, 1)
183+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
184+
defer cancel()
181185
err := cm.retryOnDisconnect(func(c *systemdDbus.Conn) error {
182-
_, err := c.StopUnitContext(context.TODO(), unitName, "replace", statusChan)
186+
_, err := c.StopUnitContext(ctx, unitName, "replace", statusChan)
183187
return err
184188
})
185189
if err == nil {

0 commit comments

Comments
 (0)