Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changelog/6520.bugfix.md
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 11 additions & 5 deletions go/oasis-node/cmd/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Loading