Skip to content

Commit

Permalink
Merge pull request #396 from dolthub/andy/fix-poll-for-closed-connection
Browse files Browse the repository at this point in the history
/server: Unwrap `netutil.ConnWithTimeouts` in pollForClosedConnection
  • Loading branch information
andy-wm-arthur authored Apr 29, 2021
2 parents c9e737f + 94fc27c commit 1e20a95
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"github.com/dolthub/vitess/go/mysql"
"github.com/dolthub/vitess/go/netutil"
"github.com/dolthub/vitess/go/sqltypes"
"github.com/dolthub/vitess/go/vt/proto/query"
"github.com/dolthub/vitess/go/vt/sqlparser"
Expand Down Expand Up @@ -452,7 +453,7 @@ func (h *Handler) errorWrappedDoQuery(
// the supplied error channel if it has. Meant to be run in a separate goroutine from the query handler routine.
// Returns immediately on platforms that can't support TCP socket checks.
func (h *Handler) pollForClosedConnection(c *mysql.Conn, errChan chan error, quit chan struct{}, query string) {
tcpConn, ok := c.Conn.(*net.TCPConn)
tcpConn, ok := maybeGetTCPConn(c.Conn)
if !ok {
logrus.Debug("Connection checker exiting, connection isn't TCP")
return
Expand Down Expand Up @@ -496,6 +497,20 @@ func (h *Handler) pollForClosedConnection(c *mysql.Conn, errChan chan error, qui
}
}

func maybeGetTCPConn(conn net.Conn) (*net.TCPConn, bool) {
wrap, ok := conn.(netutil.ConnWithTimeouts)
if ok {
conn = wrap.Conn
}

tcp, ok := conn.(*net.TCPConn)
if ok {
return tcp, true
}

return nil, false
}

func isSessionAutocommit(ctx *sql.Context) (bool, error) {
autoCommitSessionVar, err := ctx.GetSessionVariable(ctx, sql.AutoCommitSessionVar)
if err != nil {
Expand Down

0 comments on commit 1e20a95

Please sign in to comment.