From 6da3183105aa0722609029bc1a8e55775ea8bde3 Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Fri, 1 Apr 2022 20:47:06 +0000 Subject: [PATCH] Disable writing freelist to make the file robust against data corruptions A bbolt database has a freelist to track all pages that are available for allocation. However writing the list takes some time and reading the list sometimes panics. This commit sets NoFreelistSync true to skipping the freelist entirely, following what etcd does. https://github.com/etcd-io/etcd/blob/v3.5.2/server/mvcc/backend/config_linux.go#L31 Fixes #4838. Signed-off-by: Kazuyoshi Kato --- services/server/server.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/services/server/server.go b/services/server/server.go index 857cc9c76..39be7593b 100644 --- a/services/server/server.go +++ b/services/server/server.go @@ -450,8 +450,16 @@ func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]*plugin.Regis path := filepath.Join(ic.Root, "meta.db") ic.Meta.Exports["path"] = path + options := *bolt.DefaultOptions + // Reading bbolt's freelist sometimes fails when the file has a data corruption. + // Disabling freelist sync reduces the chance of the breakage. + // https://github.com/etcd-io/bbolt/pull/1 + // https://github.com/etcd-io/bbolt/pull/6 + options.NoFreelistSync = true + // Without the timeout, bbolt.Open would block indefinitely due to flock(2). options.Timeout = timeout.Get(boltOpenTimeout) + doneCh := make(chan struct{}) go func() { t := time.NewTimer(10 * time.Second)