From 04b06ba53964c02f43de5c71b85247c1b7ef1b5d Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 9 Feb 2021 18:12:09 +0300 Subject: [PATCH] [#316] locode/boltdb: Add default timeout to open underlying BoltDB instance Set timeout option of BoltDB Open operation to 3s in order to prevent indefinite waiting for file lock. Signed-off-by: Leonard Lyubich --- pkg/util/locode/db/boltdb/calls.go | 2 ++ pkg/util/locode/db/boltdb/opts.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/pkg/util/locode/db/boltdb/calls.go b/pkg/util/locode/db/boltdb/calls.go index 2aca8560..2c10aa0d 100644 --- a/pkg/util/locode/db/boltdb/calls.go +++ b/pkg/util/locode/db/boltdb/calls.go @@ -11,6 +11,8 @@ import ( ) // Open opens underlying BoltDB instance. +// +// Timeout of BoltDB opening is 3s (only for Linux or Darwin). func (db *DB) Open() error { // copy-paste from metabase: // consider universal Open/Close for BoltDB wrappers diff --git a/pkg/util/locode/db/boltdb/opts.go b/pkg/util/locode/db/boltdb/opts.go index e9eb9017..07265501 100644 --- a/pkg/util/locode/db/boltdb/opts.go +++ b/pkg/util/locode/db/boltdb/opts.go @@ -2,6 +2,7 @@ package locodebolt import ( "os" + "time" "go.etcd.io/bbolt" ) @@ -18,5 +19,8 @@ type options struct { func defaultOpts() *options { return &options{ mode: os.ModePerm, // 0777 + boltOpts: &bbolt.Options{ + Timeout: 3 * time.Second, + }, } }