Skip to content

Commit 5223bf3

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]> (cherry picked from commit e725440) Signed-off-by: Derek McGowan <[email protected]>
1 parent 8f5eba3 commit 5223bf3

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
@@ -32,6 +32,7 @@ import (
3232
"runtime"
3333
"strings"
3434
"sync"
35+
"sync/atomic"
3536
"time"
3637

3738
csapi "github.com/containerd/containerd/api/services/content/v1"
@@ -220,6 +221,7 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
220221
reqID = p.ID
221222
}
222223
log.G(ctx).WithField("type", p.Type).Infof("loading plugin %q...", id)
224+
var mustSucceed int32
223225

224226
initContext := plugin.NewContext(
225227
ctx,
@@ -231,7 +233,10 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
231233
initContext.Events = events
232234
initContext.Address = config.GRPC.Address
233235
initContext.TTRPCAddress = config.TTRPC.Address
234-
initContext.RegisterReadiness = s.RegisterReadiness
236+
initContext.RegisterReadiness = func() func() {
237+
atomic.StoreInt32(&mustSucceed, 1)
238+
return s.RegisterReadiness()
239+
}
235240

236241
// load the plugin specific configuration if it is provided
237242
if p.Config != nil {
@@ -256,6 +261,10 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
256261
if _, ok := required[reqID]; ok {
257262
return nil, fmt.Errorf("load required plugin %s: %w", id, err)
258263
}
264+
// If readiness was registered during initialization, the plugin cannot fail
265+
if atomic.LoadInt32(&mustSucceed) != 0 {
266+
return nil, fmt.Errorf("plugin failed after registering readiness %s: %w", id, err)
267+
}
259268
continue
260269
}
261270

0 commit comments

Comments
 (0)