Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit bb50508

Browse files
kolyshkinthaJeztah
authored andcommitted
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> Upstream-commit: e48913071758a56b2bd386b9f2eb38646f54613b Component: engine
1 parent ece5b0f commit bb50508

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

components/engine/daemon/monitor.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerdtypes.EventType, ei
5555
if err != nil {
5656
logrus.WithError(err).Warnf("failed to delete container %s from containerd", c.ID)
5757
}
58-
ctx, _ := context.WithTimeout(context.Background(), 2*time.Second)
59-
58+
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
6059
c.StreamConfig.Wait(ctx)
60+
cancel()
6161
c.Reset(false)
6262

6363
exitStatus := container.ExitStatus{
@@ -126,8 +126,9 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerdtypes.EventType, ei
126126
execConfig.ExitCode = &ec
127127
execConfig.Running = false
128128

129-
ctx, _ := context.WithTimeout(context.Background(), 2*time.Second)
129+
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
130130
execConfig.StreamConfig.Wait(ctx)
131+
cancel()
131132

132133
if err := execConfig.CloseStreams(); err != nil {
133134
logrus.Errorf("failed to cleanup exec %s streams: %s", c.ID, err)

0 commit comments

Comments
 (0)