Merge pull request #6225 from jonyhy96/feat-blot-open-timeout

feat: add timeout for bolt open
This commit is contained in:
Phil Estes 2021-12-13 11:22:28 -05:00 committed by GitHub
commit 6e9e759553
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,6 +61,14 @@ import (
"google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials"
) )
const (
boltOpenTimeout = "io.containerd.timeout.bolt.open"
)
func init() {
timeout.Set(boltOpenTimeout, 0) // set to 0 means to wait indefinitely for bolt.Open
}
// CreateTopLevelDirectories creates the top-level root and state directories. // CreateTopLevelDirectories creates the top-level root and state directories.
func CreateTopLevelDirectories(config *srvconfig.Config) error { func CreateTopLevelDirectories(config *srvconfig.Config) error {
switch { switch {
@ -440,8 +448,21 @@ func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]*plugin.Regis
path := filepath.Join(ic.Root, "meta.db") path := filepath.Join(ic.Root, "meta.db")
ic.Meta.Exports["path"] = path ic.Meta.Exports["path"] = path
options := *bolt.DefaultOptions
db, err := bolt.Open(path, 0644, nil) options.Timeout = timeout.Get(boltOpenTimeout)
doneCh := make(chan struct{})
go func() {
t := time.NewTimer(10 * time.Second)
defer t.Stop()
select {
case <-t.C:
log.G(ctx).WithField("plugin", "bolt").Warn("waiting for response from boltdb open")
case <-doneCh:
return
}
}()
db, err := bolt.Open(path, 0644, &options)
close(doneCh)
if err != nil { if err != nil {
return nil, err return nil, err
} }