Skip to content

Commit 008ac81

Browse files
author
Rafael Chacon
committed
Remove infinity, keep it consistent with the rest of the codebase
Signed-off-by: Rafael Chacon <rafael@slack-corp.com>
1 parent 7399bde commit 008ac81

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed

go/mysql/server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ func (l *Listener) Accept() {
174174
// handle is called in a go routine for each client connection.
175175
// FIXME(alainjobart) handle per-connection logs in a way that makes sense.
176176
func (l *Listener) handle(conn net.Conn, connectionID uint32, acceptTime time.Time) {
177-
conn = netutil.NewConnWithTimeouts(conn, l.connReadTimeout, l.connWriteTimeout)
177+
if l.connReadTimeout != 0 || l.connWriteTimeout != 0 {
178+
conn = netutil.NewConnWithTimeouts(conn, l.connReadTimeout, l.connWriteTimeout)
179+
}
178180
c := newConn(conn)
179181
c.ConnectionID = connectionID
180182

go/vt/vtgate/plugin_mysql_server.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package vtgate
1919
import (
2020
"flag"
2121
"fmt"
22-
"math"
2322
"net"
2423
"os"
2524
"sync/atomic"
@@ -40,7 +39,6 @@ import (
4039
)
4140

4241
var (
43-
infinity = time.Duration(math.MaxInt64)
4442
mysqlServerPort = flag.Int("mysql_server_port", -1, "If set, also listen for MySQL binary protocol connections on this port.")
4543
mysqlServerBindAddress = flag.String("mysql_server_bind_address", "", "Binds on this address when listening to MySQL binary protocol. Useful to restrict listening to 'localhost' only for instance.")
4644
mysqlServerSocketPath = flag.String("mysql_server_socket_path", "", "This option specifies the Unix socket file to use when listening for local connections. By default it will be empty and it won't listen to a unix socket")
@@ -55,9 +53,9 @@ var (
5553

5654
mysqlSlowConnectWarnThreshold = flag.Duration("mysql_slow_connect_warn_threshold", 0, "Warn if it takes more than the given threshold for a mysql connection to establish")
5755

58-
mysqlConnReadTimeout = flag.Duration("mysql_server_read_timeout", infinity, "connection read timeout")
59-
mysqlConnWriteTimeout = flag.Duration("mysql_server_write_timeout", infinity, "connection write timeout")
60-
mysqlQueryTimeout = flag.Duration("mysql_server_query_timeout", infinity, "mysql query timeout")
56+
mysqlConnReadTimeout = flag.Duration("mysql_server_read_timeout", 0, "connection read timeout")
57+
mysqlConnWriteTimeout = flag.Duration("mysql_server_write_timeout", 0, "connection write timeout")
58+
mysqlQueryTimeout = flag.Duration("mysql_server_query_timeout", 0, "mysql query timeout")
6159

6260
busyConnections int32
6361
)
@@ -80,8 +78,14 @@ func (vh *vtgateHandler) NewConnection(c *mysql.Conn) {
8078

8179
func (vh *vtgateHandler) ConnectionClosed(c *mysql.Conn) {
8280
// Rollback if there is an ongoing transaction. Ignore error.
83-
ctx, cancel := context.WithTimeout(context.Background(), *mysqlQueryTimeout)
84-
defer cancel()
81+
var ctx context.Context
82+
var cancel context.CancelFunc
83+
if *mysqlQueryTimeout != 0 {
84+
ctx, cancel = context.WithTimeout(context.Background(), *mysqlQueryTimeout)
85+
defer cancel()
86+
} else {
87+
ctx = context.Background()
88+
}
8589
session, _ := c.ClientData.(*vtgatepb.Session)
8690
if session != nil {
8791
if session.InTransaction {
@@ -92,8 +96,14 @@ func (vh *vtgateHandler) ConnectionClosed(c *mysql.Conn) {
9296
}
9397

9498
func (vh *vtgateHandler) ComQuery(c *mysql.Conn, query string, callback func(*sqltypes.Result) error) error {
95-
ctx, cancel := context.WithTimeout(context.Background(), *mysqlQueryTimeout)
96-
defer cancel()
99+
var ctx context.Context
100+
var cancel context.CancelFunc
101+
if *mysqlQueryTimeout != 0 {
102+
ctx, cancel = context.WithTimeout(context.Background(), *mysqlQueryTimeout)
103+
defer cancel()
104+
} else {
105+
ctx = context.Background()
106+
}
97107

98108
// Fill in the ImmediateCallerID with the UserData returned by
99109
// the AuthServer plugin for that user. If nothing was

go/vt/vtqueryserver/plugin_mysql_server.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ package vtqueryserver
1919
import (
2020
"flag"
2121
"fmt"
22-
"math"
2322
"net"
2423
"os"
2524
"syscall"
26-
"time"
2725

2826
"golang.org/x/net/context"
2927

@@ -39,7 +37,6 @@ import (
3937
)
4038

4139
var (
42-
infinity = time.Duration(math.MaxInt64)
4340
mysqlServerPort = flag.Int("mysqlproxy_server_port", -1, "If set, also listen for MySQL binary protocol connections on this port.")
4441
mysqlServerBindAddress = flag.String("mysqlproxy_server_bind_address", "", "Binds on this address when listening to MySQL binary protocol. Useful to restrict listening to 'localhost' only for instance.")
4542
mysqlServerSocketPath = flag.String("mysqlproxy_server_socket_path", "", "This option specifies the Unix socket file to use when listening for local connections. By default it will be empty and it won't listen to a unix socket")
@@ -52,9 +49,9 @@ var (
5249

5350
mysqlSlowConnectWarnThreshold = flag.Duration("mysqlproxy_slow_connect_warn_threshold", 0, "Warn if it takes more than the given threshold for a mysql connection to establish")
5451

55-
mysqlConnReadTimeout = flag.Duration("mysql_server_read_timeout", infinity, "connection read timeout")
56-
mysqlConnWriteTimeout = flag.Duration("mysql_server_write_timeout", infinity, "connection write timeout")
57-
mysqlQueryTimeout = flag.Duration("mysql_server_query_timeout", infinity, "mysql query timeout")
52+
mysqlConnReadTimeout = flag.Duration("mysql_server_read_timeout", 0, "connection read timeout")
53+
mysqlConnWriteTimeout = flag.Duration("mysql_server_write_timeout", 0, "connection write timeout")
54+
mysqlQueryTimeout = flag.Duration("mysql_server_query_timeout", 0, "mysql query timeout")
5855
)
5956

6057
// proxyHandler implements the Listener interface.
@@ -75,18 +72,29 @@ func (mh *proxyHandler) NewConnection(c *mysql.Conn) {
7572

7673
func (mh *proxyHandler) ConnectionClosed(c *mysql.Conn) {
7774
// Rollback if there is an ongoing transaction. Ignore error.
78-
ctx, cancel := context.WithTimeout(context.Background(), *mysqlQueryTimeout)
79-
defer cancel()
75+
var ctx context.Context
76+
var cancel context.CancelFunc
77+
if *mysqlQueryTimeout != 0 {
78+
ctx, cancel = context.WithTimeout(context.Background(), *mysqlQueryTimeout)
79+
defer cancel()
80+
} else {
81+
ctx = context.Background()
82+
}
8083
session, _ := c.ClientData.(*mysqlproxy.ProxySession)
8184
if session != nil && session.TransactionID != 0 {
8285
_ = mh.mp.Rollback(ctx, session)
8386
}
8487
}
8588

8689
func (mh *proxyHandler) ComQuery(c *mysql.Conn, query string, callback func(*sqltypes.Result) error) error {
87-
ctx, cancel := context.WithTimeout(context.Background(), *mysqlQueryTimeout)
88-
defer cancel()
89-
90+
var ctx context.Context
91+
var cancel context.CancelFunc
92+
if *mysqlQueryTimeout != 0 {
93+
ctx, cancel = context.WithTimeout(context.Background(), *mysqlQueryTimeout)
94+
defer cancel()
95+
} else {
96+
ctx = context.Background()
97+
}
9098
// Fill in the ImmediateCallerID with the UserData returned by
9199
// the AuthServer plugin for that user. If nothing was
92100
// returned, use the User. This lets the plugin map a MySQL

0 commit comments

Comments
 (0)