@@ -34,9 +34,26 @@ func (m *Message) ExitTime() time.Time {
3434
3535type watch struct {
3636 sync.Mutex
37- //client *containerd.Client
3837 containers map [string ]* containerPack
3938 hooks []func (string , * Message ) error
39+
40+ // containerdDead to specify whether containerd process is dead
41+ containerdDead bool
42+ }
43+
44+ func (w * watch ) setContainerdDead (isDead bool ) error {
45+ w .Lock ()
46+ defer w .Unlock ()
47+
48+ w .containerdDead = isDead
49+ return nil
50+ }
51+
52+ func (w * watch ) isContainerdDead () bool {
53+ w .Lock ()
54+ defer w .Unlock ()
55+
56+ return w .containerdDead
4057}
4158
4259func (w * watch ) add (pack * containerPack ) {
@@ -49,9 +66,16 @@ func (w *watch) add(pack *containerPack) {
4966
5067 w .containers [pack .id ] = pack
5168
52- go func (pack * containerPack ) {
69+ go func (w * watch , pack * containerPack ) {
5370 status := <- pack .sch
5471
72+ // if containerd is dead, the task.Wait channel return is not because
73+ // container' task quit, but the channel has broken.
74+ // so we just return.
75+ if w .isContainerdDead () {
76+ return
77+ }
78+
5579 logrus .Infof ("the task has quit, id: %s, err: %v, exitcode: %d, time: %v" ,
5680 pack .id , status .Error (), status .ExitCode (), status .ExitTime ())
5781
@@ -85,7 +109,7 @@ func (w *watch) add(pack *containerPack) {
85109
86110 pack .ch <- msg
87111
88- }(pack )
112+ }(w , pack )
89113
90114 logrus .Infof ("success to add container, id: %s" , pack .id )
91115}
0 commit comments