github.com/rish1988/moby@v25.0.2+incompatible/container/monitor.go (about) 1 package container // import "github.com/docker/docker/container" 2 3 import ( 4 "context" 5 "time" 6 7 "github.com/containerd/log" 8 ) 9 10 const ( 11 loggerCloseTimeout = 10 * time.Second 12 ) 13 14 // Reset puts a container into a state where it can be restarted again. 15 func (container *Container) Reset(lock bool) { 16 if lock { 17 container.Lock() 18 defer container.Unlock() 19 } 20 21 if err := container.CloseStreams(); err != nil { 22 log.G(context.TODO()).Errorf("%s: %s", container.ID, err) 23 } 24 25 // Re-create a brand new stdin pipe once the container exited 26 if container.Config.OpenStdin { 27 container.StreamConfig.NewInputPipes() 28 } 29 30 if container.LogDriver != nil { 31 if container.LogCopier != nil { 32 exit := make(chan struct{}) 33 go func() { 34 container.LogCopier.Wait() 35 close(exit) 36 }() 37 38 timer := time.NewTimer(loggerCloseTimeout) 39 defer timer.Stop() 40 select { 41 case <-timer.C: 42 log.G(context.TODO()).Warn("Logger didn't exit in time: logs may be truncated") 43 case <-exit: 44 } 45 } 46 container.LogDriver.Close() 47 container.LogCopier = nil 48 container.LogDriver = nil 49 } 50 }