Skip to content

fix: use TCP as default protocol #374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2023
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
3 changes: 0 additions & 3 deletions pkg/sqlcmd/sqlcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import (
"golang.org/x/text/transform"
)

// Note: The order of includes above matters for namedpipe and sharedmemory.
// init() swaps shared memory protocol with tcp so it gets priority when dialing.

var (
// ErrExitRequested tells the hosting application to exit immediately
ErrExitRequested = errors.New("exit")
Expand Down
6 changes: 3 additions & 3 deletions pkg/sqlcmd/sqlcmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,9 +644,9 @@ func TestSqlcmdPrefersSharedMemoryProtocol(t *testing.T) {
if runtime.GOOS != "windows" || runtime.GOARCH != "amd64" {
t.Skip("Only valid on Windows amd64")
}
assert.EqualValuesf(t, "lpc", msdsn.ProtocolParsers[0].Protocol(), "lpc should be first protocol")
assert.EqualValuesf(t, "lpc", msdsn.ProtocolParsers[2].Protocol(), "lpc should be third protocol")
assert.Truef(t, msdsn.ProtocolParsers[1].Hidden(), "Protocol %s should be hidden", msdsn.ProtocolParsers[1].Protocol())
assert.EqualValuesf(t, "tcp", msdsn.ProtocolParsers[2].Protocol(), "tcp should be second protocol")
assert.EqualValuesf(t, "np", msdsn.ProtocolParsers[3].Protocol(), "np should be third protocol")
assert.EqualValuesf(t, "tcp", msdsn.ProtocolParsers[0].Protocol(), "tcp should be first protocol")
assert.EqualValuesf(t, "np", msdsn.ProtocolParsers[3].Protocol(), "np should be fourth protocol")

}
14 changes: 9 additions & 5 deletions pkg/sqlcmd/sqlcmd_windows_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import (
_ "github.com/microsoft/go-mssqldb/sharedmemory"
)

// Note: The order of includes above matters for namedpipe and sharedmemory.
// Go tools always sort by name.
// init() swaps shared memory protocol with np so it gets priority when dialing.

func init() {
if len(msdsn.ProtocolParsers) == 4 {
// reorder the protocol parsers to lpc->admin->tcp->np
// ODBC follows this same order.
// reorder the protocol parsers to tcp->admin->lpc->np
// Named pipes/shared memory package doesn't support ARM
var tcp = msdsn.ProtocolParsers[0]
msdsn.ProtocolParsers[0] = msdsn.ProtocolParsers[3]
// Once there's a fix for https://github.com/natefinch/npipe/issues/34 incorporated into go-mssqldb,
// reorder to lpc->admin->np->tcp
var lpc = msdsn.ProtocolParsers[3]
msdsn.ProtocolParsers[3] = msdsn.ProtocolParsers[2]
msdsn.ProtocolParsers[2] = tcp
msdsn.ProtocolParsers[2] = lpc
}
}