Skip to content

Commit

Permalink
cmd/connect: handle Windows socket error 10013 (WSAEACCES)
Browse files Browse the repository at this point in the history
This PR makes sure to also handle the case when a socket fails to bind to socket with exclusive access. For more information checkout the docs for the code `10013`: https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2

fixes: #265
  • Loading branch information
fatih committed May 24, 2021
1 parent 7e38647 commit acbc92c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions internal/cmd/connect/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"runtime"
"syscall"

"github.com/mattn/go-shellwords"
"github.com/planetscale/cli/internal/cmdutil"
"github.com/planetscale/cli/internal/printer"
"github.com/planetscale/cli/internal/promptutil"
"github.com/planetscale/cli/internal/proxyutil"
"github.com/planetscale/planetscale-go/planetscale"

"github.com/mattn/go-shellwords"
"github.com/planetscale/sql-proxy/proxy"
"github.com/planetscale/sql-proxy/sigutil"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -211,9 +211,22 @@ func isAddrInUse(err error) bool {
return true
}

const WSAEADDRINUSE = 10048
if runtime.GOOS == "windows" && errErrno == WSAEADDRINUSE {
return true
if runtime.GOOS == "windows" {
// Looks like on Windows we might see multiple different errors. Here
// are some information on how to track them down.
// There is a list of human readable Windows errors here: https://github.com/benmoss/monitor/blob/8bcb512752ea0d322e0498309ab2cc1821090f01/errno/msg.go
// The errors constants map to the syscall codes defined in: https://pkg.go.dev/golang.org/x/sys/windows
// The official docs for some windows socket errors are here: // https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2
const (
WSAEACCES = 10013
WSAEADDRINUSE = 10048
)

switch errErrno {
case WSAEACCES, WSAEADDRINUSE:
return true
}
}

return false
}

0 comments on commit acbc92c

Please sign in to comment.