Skip to content

Commit

Permalink
Handle windows case for the node not running in network switch (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmmarslender authored Feb 6, 2025
1 parent d18f5f2 commit 38c08d8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cmd/network/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/chia-network/go-modules/pkg/slogs"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/chia-network/chia-tools/internal/connect"
)

var switchCmd = &cobra.Command{
Expand Down Expand Up @@ -304,7 +306,13 @@ func isConnectionRefused(err error) bool {
if netErr.Op == "dial" {
var syscallError *os.SyscallError
if errors.As(netErr.Err, &syscallError) {
return syscallError.Syscall == "connect" && errors.Is(syscallError.Err, syscall.ECONNREFUSED)
if syscallError.Syscall == "connect" && errors.Is(syscallError.Err, syscall.ECONNREFUSED) {
return true
}
// Handle Windows-specific case
if connect.IsWindowsConnectionRefused(err) {
return true
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions internal/connect/nonwindows_conn_refused.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build !windows

package connect

// IsWindowsConnectionRefused is a no-op on non-Windows systems.
func IsWindowsConnectionRefused(err error) bool {
return false
}
14 changes: 14 additions & 0 deletions internal/connect/windows_conn_refused.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build windows

package connect

import (
"errors"

"golang.org/x/sys/windows"
)

// IsWindowsConnectionRefused checks if the error is a Windows-specific connection refused error.
func IsWindowsConnectionRefused(err error) bool {
return errors.Is(err, windows.WSAECONNREFUSED)
}

0 comments on commit 38c08d8

Please sign in to comment.