From 6a3b8231094acaf02a9aa550e3f86eae777f7cbe Mon Sep 17 00:00:00 2001 From: Martin Tomazic Date: Mon, 4 May 2026 13:41:36 +0200 Subject: [PATCH] go/oasis-node/cmd/common: Fix isNodeRunning function --- .changelog/6520.bugfix.md | 4 ++++ go/oasis-node/cmd/common/common.go | 16 +++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 .changelog/6520.bugfix.md diff --git a/.changelog/6520.bugfix.md b/.changelog/6520.bugfix.md new file mode 100644 index 00000000000..71165cec703 --- /dev/null +++ b/.changelog/6520.bugfix.md @@ -0,0 +1,4 @@ +go/oasis-node/cmd/common: Fix is node running helper + +Now the helper tries to dial the node socket to check +whether the node is running. diff --git a/go/oasis-node/cmd/common/common.go b/go/oasis-node/cmd/common/common.go index 14efa632f11..699420418ed 100644 --- a/go/oasis-node/cmd/common/common.go +++ b/go/oasis-node/cmd/common/common.go @@ -6,9 +6,12 @@ import ( "fmt" "io" "io/fs" + "net" "os" "path/filepath" "strings" + "syscall" + "time" "github.com/spf13/cobra" flag "github.com/spf13/pflag" @@ -77,11 +80,14 @@ func InternalSocketPath() string { func IsNodeRunning() (bool, error) { path := InternalSocketPath() - if _, err := os.Stat(path); err != nil { - if errors.Is(err, fs.ErrNotExist) { - return false, nil - } - return false, fmt.Errorf("stat %s: %w", path, err) + conn, err := net.DialTimeout("unix", path, time.Second) + switch { + case err == nil: + _ = conn.Close() + case errors.Is(err, fs.ErrNotExist) || errors.Is(err, syscall.ECONNREFUSED): + return false, nil + default: + return false, fmt.Errorf("failed to dial internal socket %s: %w", path, err) } return true, nil