Skip to content

Commit e725440

Browse files
committed
Require plugins to succeed after registering readiness
When readiness is registered on initialization, the plugin must not fail. When such a plugin fails, containerd will hang on the readiness condition. Signed-off-by: Derek McGowan <[email protected]>
1 parent bcd658c commit e725440

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

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"
@@ -205,6 +206,7 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
205206
for _, p := range plugins {
206207
id := p.URI()
207208
log.G(ctx).WithField("type", p.Type).Infof("loading plugin %q...", id)
209+
var mustSucceed int32
208210

209211
initContext := plugin.NewContext(
210212
ctx,
@@ -215,7 +217,10 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
215217
)
216218
initContext.Address = config.GRPC.Address
217219
initContext.TTRPCAddress = config.TTRPC.Address
218-
initContext.RegisterReadiness = s.RegisterReadiness
220+
initContext.RegisterReadiness = func() func() {
221+
atomic.StoreInt32(&mustSucceed, 1)
222+
return s.RegisterReadiness()
223+
}
219224

220225
// load the plugin specific configuration if it is provided
221226
if p.Config != nil {
@@ -240,6 +245,10 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
240245
if _, ok := required[id]; ok {
241246
return nil, fmt.Errorf("load required plugin %s: %w", id, err)
242247
}
248+
// If readiness was registered during initialization, the plugin cannot fail
249+
if atomic.LoadInt32(&mustSucceed) != 0 {
250+
return nil, fmt.Errorf("plugin failed after registering readiness %s: %w", id, err)
251+
}
243252
continue
244253
}
245254

0 commit comments

Comments
 (0)