Repository navigation
shim: optimize reap to prevent event lost - #13544
ningmingxiao wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR changes the SIGCHLD reaping flow to enqueue exit events and notify subscribers asynchronously via a background goroutine.
Changes:
- Introduces a
SafeList-backed global event queue and anotify()goroutine started ininit() - Updates
reap()to push exit events into the queue instead of returning an exit slice - Adds logging + increases the wait timeout while notifying subscribers
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4be9d68 to
77389ae
Compare
77389ae to
df57285
Compare
| func notify() { | ||
| go func() { | ||
| for { | ||
| event := eventQueue.Pop() | ||
| if exitEvt, ok := event.(eventExit); ok { | ||
| done := Default.notify(runc.Exit{ | ||
| Timestamp: exitEvt.EventTime, | ||
| Pid: exitEvt.Pid, | ||
| Status: exitEvt.Status, | ||
| }) | ||
| select { | ||
| case <-done: | ||
| // TODO: delete time out | ||
| case <-time.After(30 * time.Second): | ||
| log.L.Warnf("event with pid %d status:%d may be lost", exitEvt.Pid, exitEvt.Status) | ||
| } | ||
| } | ||
| } | ||
| }() | ||
| } |
| var ( | ||
| once sync.Once | ||
| eventQueue = NewSafeList() | ||
| // ErrNoSuchProcess is returned when the process no longer exists | ||
| ErrNoSuchProcess = errors.New("no such process") | ||
| ) |
| func (sl *SafeList) Push(value any) { | ||
| sl.mu.Lock() | ||
| defer sl.mu.Unlock() | ||
|
|
||
| sl.queue.PushBack(value) | ||
| sl.cond.Signal() | ||
| } | ||
|
|
||
| func (sl *SafeList) Pop() any { | ||
| sl.mu.Lock() | ||
| defer sl.mu.Unlock() | ||
|
|
||
| for sl.queue.Len() == 0 { | ||
| sl.cond.Wait() | ||
| } | ||
| elem := sl.queue.Front() | ||
| value := elem.Value | ||
| sl.queue.Remove(elem) | ||
| return value | ||
| } |
| select { | ||
| case <-done: | ||
| // TODO: delete time out | ||
| case <-time.After(30 * time.Second): | ||
| log.L.Warnf("event with pid %d status:%d may be lost", exitEvt.Pid, exitEvt.Status) | ||
| } |
| }) | ||
| select { | ||
| case <-done: | ||
| // TODO: delete time out |
Signed-off-by: ningmingxiao <[email protected]>
df57285 to
080c3da
Compare
|
@ningmingxiao Thanks for the reproduction and for opening this PR! Your After further investigation, I found that the root cause of #12678 is actually in the CRI plugin layer, not the reaper. When I'll open a separate fix for that (move |
|
ping @samuelkarp @fuweid |
root reason
if notify timeout the exit event may lost
try to reduce the probability of container event loss try fix #12678
reproduce
after pod is running
echo 11> /tmp/debug2
4 . kill -9
pidof sleep5.crictl ps |grep sleep |wc -l
containerd --version
containerd github.com/containerd/containerd v1.7.27 05044ec
shim stack
666666.txt
repeat log
ctr -n k8s.io t ls|grep ddd is hanging