@@ -32,6 +32,7 @@ import (
3232 "github.com/containerd/containerd/identifiers"
3333 "github.com/containerd/containerd/log"
3434 "github.com/containerd/containerd/namespaces"
35+ "github.com/containerd/containerd/pkg/timeout"
3536 "github.com/containerd/containerd/runtime"
3637 client "github.com/containerd/containerd/runtime/v2/shim"
3738 "github.com/containerd/containerd/runtime/v2/task"
@@ -41,6 +42,18 @@ import (
4142 "github.com/sirupsen/logrus"
4243)
4344
45+ const (
46+ loadTimeout = "io.containerd.timeout.shim.load"
47+ cleanupTimeout = "io.containerd.timeout.shim.cleanup"
48+ shutdownTimeout = "io.containerd.timeout.shim.shutdown"
49+ )
50+
51+ func init () {
52+ timeout .Set (loadTimeout , 5 * time .Second )
53+ timeout .Set (cleanupTimeout , 5 * time .Second )
54+ timeout .Set (shutdownTimeout , 3 * time .Second )
55+ }
56+
4457func loadAddress (path string ) (string , error ) {
4558 data , err := ioutil .ReadFile (path )
4659 if err != nil {
@@ -100,7 +113,7 @@ func loadShim(ctx context.Context, bundle *Bundle, events *exchange.Exchange, rt
100113 events : events ,
101114 rtTasks : rt ,
102115 }
103- ctx , cancel := context . WithTimeout (ctx , 5 * time . Second )
116+ ctx , cancel := timeout . WithContext (ctx , loadTimeout )
104117 defer cancel ()
105118 if err := s .Connect (ctx ); err != nil {
106119 return nil , err
@@ -110,7 +123,7 @@ func loadShim(ctx context.Context, bundle *Bundle, events *exchange.Exchange, rt
110123
111124func cleanupAfterDeadShim (ctx context.Context , id , ns string , events * exchange.Exchange , binaryCall * binary ) {
112125 ctx = namespaces .WithNamespace (ctx , ns )
113- ctx , cancel := context . WithTimeout (ctx , 5 * time . Second )
126+ ctx , cancel := timeout . WithContext (ctx , cleanupTimeout )
114127 defer cancel ()
115128
116129 log .G (ctx ).WithFields (logrus.Fields {
@@ -185,7 +198,7 @@ func (s *shim) Shutdown(ctx context.Context) error {
185198}
186199
187200func (s * shim ) waitShutdown (ctx context.Context ) error {
188- ctx , cancel := context . WithTimeout (ctx , 3 * time . Second )
201+ ctx , cancel := timeout . WithContext (ctx , shutdownTimeout )
189202 defer cancel ()
190203 return s .Shutdown (ctx )
191204}
0 commit comments