Skip to content

Commit 683c63f

Browse files
committed
restore: Cleanup orphaned exit files leaked before
This should clean up the exit files that we leaked before. Signed-off-by: Mrunal Patel <[email protected]>
1 parent 4477b9d commit 683c63f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

server/server.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,37 @@ func (s *Server) restore() {
221221
}
222222
sb.AddIP(ip)
223223
}
224+
225+
// Clean up orphaned exit files
226+
var exitIDs []string
227+
228+
exitDir := s.Config().RuntimeConfig.ContainerExitsDir
229+
err = filepath.Walk(exitDir, func(path string, info os.FileInfo, err error) error {
230+
exitFileName := filepath.Base(path)
231+
if path != exitDir {
232+
exitIDs = append(exitIDs, exitFileName)
233+
}
234+
return nil
235+
})
236+
if err != nil {
237+
logrus.Warnf("Failed to walk exit dir %v: %v", exitDir, err)
238+
}
239+
for _, exitID := range exitIDs {
240+
logrus.Warnf("Checking exit file: %v", exitID)
241+
ctr := s.GetContainer(exitID)
242+
if ctr != nil {
243+
continue
244+
} else {
245+
sb := s.GetSandbox(exitID)
246+
if sb != nil {
247+
continue
248+
}
249+
}
250+
logrus.Warnf("Removing exit file: %v", exitID)
251+
if err := os.Remove(filepath.Join(exitDir, exitID)); err != nil && !os.IsNotExist(err) {
252+
logrus.Warnf("Failed to remove container exit file during restore cleanup %s: %v", exitID, err)
253+
}
254+
}
224255
}
225256

226257
// cleanupSandboxesOnShutdown Remove all running Sandboxes on system shutdown

0 commit comments

Comments
 (0)