Skip to content

Commit a83c668

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 171d768 commit a83c668

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"
@@ -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)