Skip to content

Commit b05c9dd

Browse files
committed
set default port when port is not available (like with bufconn)
1 parent 11be570 commit b05c9dd

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

server/server.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,26 @@ func portInUse(hostPort string) bool {
119119
return false
120120
}
121121

122-
func updateSystemVariables(cfg mysql.ListenerConfig) error {
122+
func getPortOrDefault(cfg mysql.ListenerConfig) int64 {
123+
// TODO read this values from systemVars
124+
defaultPort := int64(3606)
123125
_, port, err := net.SplitHostPort(cfg.Listener.Addr().String())
124126
if err != nil {
125-
return err
127+
return defaultPort
126128
}
127129
portInt, err := strconv.ParseInt(port, 10, 64)
128130
if err != nil {
129-
return err
131+
return defaultPort
130132
}
133+
return portInt
134+
}
135+
136+
func updateSystemVariables(cfg mysql.ListenerConfig) error {
137+
port := getPortOrDefault(cfg)
138+
131139
// TODO: add the rest of the config variables
132-
err = sql.SystemVariables.AssignValues(map[string]interface{}{
133-
"port": portInt,
140+
err := sql.SystemVariables.AssignValues(map[string]interface{}{
141+
"port": port,
134142
"max_connections": cfg.MaxConns,
135143
"net_read_timeout": cfg.ConnReadTimeout.Seconds(),
136144
"net_write_timeout": cfg.ConnWriteTimeout.Seconds(),

server/server_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
gsql "github.com/dolthub/go-mysql-server/sql"
1919
)
2020

21-
// TestSeverCustomListener verifies a caller can provide their own net.Conn implementation for the server to use
22-
func TestSeverCustomListener(t *testing.T) {
21+
// TestServerCustomListener verifies a caller can provide their own net.Conn implementation for the server to use
22+
func TestServerCustomListener(t *testing.T) {
2323
dbName := "mydb"
2424
// create a net.Conn thats based on a golang buffer
2525
buffer := 1024

0 commit comments

Comments
 (0)