Skip to content

Commit 790f6d9

Browse files
authored
Merge pull request #9165 from dmcgowan/backport-1.7-readiness-hang-fix
[release/1.7] Require plugins to succeed after registering readiness
2 parents 7a75a30 + a83c668 commit 790f6d9

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

pkg/cri/cri.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ func init() {
5454
}
5555

5656
func initCRIService(ic *plugin.InitContext) (interface{}, error) {
57-
ready := ic.RegisterReadiness()
5857
ic.Meta.Platforms = []imagespec.Platform{platforms.DefaultSpec()}
5958
ic.Meta.Exports = map[string]string{"CRIVersion": constants.CRIVersion, "CRIVersionAlpha": constants.CRIVersionAlpha}
6059
ctx := ic.Context
@@ -99,6 +98,8 @@ func initCRIService(ic *plugin.InitContext) (interface{}, error) {
9998
return nil, fmt.Errorf("failed to create CRI service: %w", err)
10099
}
101100

101+
// RegisterReadiness() must be called after NewCRIService(): https://github.com/containerd/containerd/issues/9163
102+
ready := ic.RegisterReadiness()
102103
go func() {
103104
if err := s.Run(ready); err != nil {
104105
log.G(ctx).WithError(err).Fatal("Failed to run CRI service")

services/server/server.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"path/filepath"
3232
"runtime"
3333
"sync"
34+
"sync/atomic"
3435
"time"
3536

3637
csapi "github.com/containerd/containerd/api/services/content/v1"
@@ -209,6 +210,7 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
209210
reqID = p.ID
210211
}
211212
log.G(ctx).WithField("type", p.Type).Infof("loading plugin %q...", id)
213+
var mustSucceed int32
212214

213215
initContext := plugin.NewContext(
214216
ctx,
@@ -220,7 +222,10 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
220222
initContext.Events = events
221223
initContext.Address = config.GRPC.Address
222224
initContext.TTRPCAddress = config.TTRPC.Address
223-
initContext.RegisterReadiness = s.RegisterReadiness
225+
initContext.RegisterReadiness = func() func() {
226+
atomic.StoreInt32(&mustSucceed, 1)
227+
return s.RegisterReadiness()
228+
}
224229

225230
// load the plugin specific configuration if it is provided
226231
if p.Config != nil {
@@ -245,6 +250,10 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
245250
if _, ok := required[reqID]; ok {
246251
return nil, fmt.Errorf("load required plugin %s: %w", id, err)
247252
}
253+
// If readiness was registered during initialization, the plugin cannot fail
254+
if atomic.LoadInt32(&mustSucceed) != 0 {
255+
return nil, fmt.Errorf("plugin failed after registering readiness %s: %w", id, err)
256+
}
248257
continue
249258
}
250259

0 commit comments

Comments
 (0)