Skip to content

Agent Mesh

improve failure

Antonio Ojea8e34e45458e7
diff --git a/cmd/sam-node/main.go b/cmd/sam-node/main.go
index 8374a25b..acc68983 100644
--- a/cmd/sam-node/main.go
+++ b/cmd/sam-node/main.go
@@ -434,6 +434,7 @@ func main() {
<-sigChan
fmt.Println("\n[Signal] Received interrupt, shutting down...")
cancel()
+ signal.Stop(sigChan)
}()
if err := rootCmd.ExecuteContext(ctx); err != nil {
diff --git a/cmd/sam-node/store.go b/cmd/sam-node/store.go
index 2e57626e..6380b230 100644
--- a/cmd/sam-node/store.go
+++ b/cmd/sam-node/store.go
@@ -19,9 +19,11 @@ import (
"fmt"
"os"
"path/filepath"
+ "time"
"github.com/libp2p/go-libp2p/core/peer"
"go.etcd.io/bbolt"
+ bbolterrors "go.etcd.io/bbolt/errors"
)
const (
@@ -49,8 +51,11 @@ func GetDefaultDataDir() (string, error) {
func NewStore(dir string) (*Store, error) {
dbPath := filepath.Join(dir, "agent.db")
- db, err := bbolt.Open(dbPath, 0600, nil)
+ db, err := bbolt.Open(dbPath, 0600, &bbolt.Options{Timeout: 5 * time.Second})
if err != nil {
+ if err == bbolterrors.ErrTimeout {
+ return nil, fmt.Errorf("timeout waiting for file lock, is another instance of sam-node running?")
+ }
return nil, err
}