Skip to content

Commit 5c68f56

Browse files
authored
Merge pull request kubernetes#122781 from pacoxu/fix-channel-panic
kubelet: delete channel from the terminated after closing it
2 parents 08a66e0 + 3c7cf37 commit 5c68f56

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pkg/kubelet/kuberuntime/kuberuntime_termination_order.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package kuberuntime
1818

1919
import (
20+
"sync"
2021
"time"
2122

2223
v1 "k8s.io/api/core/v1"
@@ -34,6 +35,8 @@ type terminationOrdering struct {
3435
// prereqs is a map from container name to a list of channel that the container
3536
// must wait on to ensure termination ordering
3637
prereqs map[string][]chan struct{}
38+
39+
lock sync.Mutex
3740
}
3841

3942
// newTerminationOrdering constructs a terminationOrdering based on the pod spec and the currently running containers.
@@ -114,9 +117,12 @@ func (o *terminationOrdering) waitForTurn(name string, gracePeriod int64) float6
114117
return time.Since(start).Seconds()
115118
}
116119

117-
// containerTerminated should be called once the container with the speecified name has exited.
120+
// containerTerminated should be called once the container with the specified name has exited.
118121
func (o *terminationOrdering) containerTerminated(name string) {
122+
o.lock.Lock()
123+
defer o.lock.Unlock()
119124
if ch, ok := o.terminated[name]; ok {
120125
close(ch)
126+
delete(o.terminated, name)
121127
}
122128
}

0 commit comments

Comments
 (0)