Skip to content

Commit c297384

Browse files
gollerjedevc
authored andcommitted
fix(boltdb): close cache and history dbs on exit
Signed-off-by: Chris Goller <[email protected]> (cherry picked from commit 4d4fc4d) Signed-off-by: Justin Chadwell <[email protected]>
1 parent 66df2da commit c297384

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

cmd/buildkitd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ func newController(c *cli.Context, cfg *config.Config) (*control.Controller, err
722722
Entitlements: cfg.Entitlements,
723723
TraceCollector: tc,
724724
HistoryDB: historyDB,
725+
CacheStore: cacheStorage,
725726
LeaseManager: w.LeaseManager(),
726727
ContentStore: w.ContentStore(),
727728
HistoryConfig: cfg.History,

control/control.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/containerd/containerd/content"
1313
"github.com/containerd/containerd/services/content/contentserver"
1414
"github.com/docker/distribution/reference"
15+
"github.com/hashicorp/go-multierror"
1516
"github.com/mitchellh/hashstructure/v2"
1617
controlapi "github.com/moby/buildkit/api/services/control"
1718
apitypes "github.com/moby/buildkit/api/types"
@@ -29,6 +30,7 @@ import (
2930
"github.com/moby/buildkit/session/grpchijack"
3031
containerdsnapshot "github.com/moby/buildkit/snapshot/containerd"
3132
"github.com/moby/buildkit/solver"
33+
"github.com/moby/buildkit/solver/bboltcachestorage"
3234
"github.com/moby/buildkit/solver/llbsolver"
3335
"github.com/moby/buildkit/solver/llbsolver/proc"
3436
"github.com/moby/buildkit/solver/pb"
@@ -61,6 +63,7 @@ type Opt struct {
6163
Entitlements []string
6264
TraceCollector sdktrace.SpanExporter
6365
HistoryDB *bbolt.DB
66+
CacheStore *bboltcachestorage.Store
6467
LeaseManager *leaseutil.Manager
6568
ContentStore *containerdsnapshot.Store
6669
HistoryConfig *config.HistoryConfig
@@ -123,7 +126,16 @@ func NewController(opt Opt) (*Controller, error) {
123126
}
124127

125128
func (c *Controller) Close() error {
126-
return c.opt.WorkerController.Close()
129+
rerr := c.opt.HistoryDB.Close()
130+
if err := c.opt.WorkerController.Close(); err != nil {
131+
rerr = multierror.Append(rerr, err)
132+
}
133+
134+
if err := c.opt.CacheStore.Close(); err != nil {
135+
rerr = multierror.Append(rerr, err)
136+
}
137+
138+
return rerr
127139
}
128140

129141
func (c *Controller) Register(server *grpc.Server) {

solver/bboltcachestorage/storage.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ func (s *Store) Exists(id string) bool {
5454
return exists
5555
}
5656

57+
func (s *Store) Close() error {
58+
return s.db.Close()
59+
}
60+
5761
func (s *Store) Walk(fn func(id string) error) error {
5862
ids := make([]string, 0)
5963
if err := s.db.View(func(tx *bolt.Tx) error {

0 commit comments

Comments
 (0)