Skip to content

Commit 877b326

Browse files
committed
Handle windows case for the node not running in network switch
1 parent d18f5f2 commit 877b326

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

cmd/network/switch.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"github.com/chia-network/go-modules/pkg/slogs"
1515
"github.com/spf13/cobra"
1616
"github.com/spf13/viper"
17+
18+
"github.com/chia-network/chia-tools/internal/connect"
1719
)
1820

1921
var switchCmd = &cobra.Command{
@@ -304,7 +306,13 @@ func isConnectionRefused(err error) bool {
304306
if netErr.Op == "dial" {
305307
var syscallError *os.SyscallError
306308
if errors.As(netErr.Err, &syscallError) {
307-
return syscallError.Syscall == "connect" && errors.Is(syscallError.Err, syscall.ECONNREFUSED)
309+
if syscallError.Syscall == "connect" && errors.Is(syscallError.Err, syscall.ECONNREFUSED) {
310+
return true
311+
}
312+
// Handle Windows-specific case
313+
if connect.IsWindowsConnectionRefused(err) {
314+
return true
315+
}
308316
}
309317
}
310318
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//go:build !windows
2+
3+
package connect
4+
5+
// IsWindowsConnectionRefused is a no-op on non-Windows systems.
6+
func IsWindowsConnectionRefused(err error) bool {
7+
return false
8+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//go:build windows
2+
3+
package connect
4+
5+
import (
6+
"errors"
7+
8+
"golang.org/x/sys/windows"
9+
)
10+
11+
// IsWindowsConnectionRefused checks if the error is a Windows-specific connection refused error.
12+
func IsWindowsConnectionRefused(err error) bool {
13+
return errors.Is(err, windows.WSAECONNREFUSED)
14+
}

0 commit comments

Comments
 (0)