Skip to content

Commit 84abe7b

Browse files
committed
fix: timeout containers should be cleanup by onPostSync()
It's noticed that timeout containers are not removed properly, and it still shows "syncing" in metadata.
1 parent 0ff26be commit 84abe7b

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pkg/server/main.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,14 @@ func (s *Server) waitForSync(ct *api.Container) error {
406406

407407
code, err := s.c.WaitContainer(ctx, ct.ID)
408408
if err != nil {
409-
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
410-
// timeout, we should stop the container
411-
ctx, cancel := context.WithTimeout(s.context(), time.Second*30)
412-
_ = s.c.StopContainer(ctx, ct.ID)
413-
cancel()
409+
if !errors.Is(ctx.Err(), context.DeadlineExceeded) {
410+
return err
411+
} else {
412+
// When the error is timeout, we expect that
413+
// container will be stopped and removed in onPostSync() goroutine
414+
// Here we set a special exit code to indicate that the container is timeout in meta.
415+
code = -2
414416
}
415-
return err
416417
}
417418

418419
name, ok := ct.Labels["org.ustcmirror.name"]
@@ -430,5 +431,7 @@ func (s *Server) waitForSync(ct *api.Container) error {
430431
Dir: dir,
431432
ExitCode: code,
432433
}
433-
return nil
434+
// returns context.DeadlineExceeded when timeout
435+
// or nil when it succeeded
436+
return err
434437
}

0 commit comments

Comments
 (0)