Browse code

daemon/ProcessEvent: make sure to cancel the contexts

Reported by govet linter:

> daemon/monitor.go:57:9: lostcancel: the cancel function returned by context.WithTimeout should be called, not discarded, to avoid a context leak (govet)
> ctx, _ := context.WithTimeout(context.Background(), 2*time.Second)
> ^
> daemon/monitor.go:128:9: lostcancel: the cancel function returned by context.WithTimeout should be called, not discarded, to avoid a context leak (govet)
> ctx, _ := context.WithTimeout(context.Background(), 2*time.Second)
> ^

Fixes: b5f288 ("Handle blocked I/O of exec'd processes")
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 53cbf1797b001314035a13578ed60f015a0179e4)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Kir Kolyshkin authored on 2019/08/06 11:18:54
Showing 1 changed files
... ...
@@ -55,9 +55,9 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerdtypes.EventType, ei
55 55
 			if err != nil {
56 56
 				logrus.WithError(err).Warnf("failed to delete container %s from containerd", c.ID)
57 57
 			}
58
-			ctx, _ := context.WithTimeout(context.Background(), 2*time.Second)
59
-
58
+			ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
60 59
 			c.StreamConfig.Wait(ctx)
60
+			cancel()
61 61
 			c.Reset(false)
62 62
 
63 63
 			exitStatus := container.ExitStatus{
... ...
@@ -126,8 +126,9 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerdtypes.EventType, ei
126 126
 			execConfig.ExitCode = &ec
127 127
 			execConfig.Running = false
128 128
 
129
-			ctx, _ := context.WithTimeout(context.Background(), 2*time.Second)
129
+			ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
130 130
 			execConfig.StreamConfig.Wait(ctx)
131
+			cancel()
131 132
 
132 133
 			if err := execConfig.CloseStreams(); err != nil {
133 134
 				logrus.Errorf("failed to cleanup exec %s streams: %s", c.ID, err)