Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
Fixes from review
Browse files Browse the repository at this point in the history
Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>
  • Loading branch information
Juanjo Alvarez committed Aug 12, 2019
1 parent a37b443 commit 7462152
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (

var regKillCmd = regexp.MustCompile(`^kill (?:(query|connection) )?(\d+)$`)

var errConnectionNotFound = errors.NewKind("Connection not found: %c")
var RowTimeout = errors.NewKind("Row read wait bigger than connection timeout")
var errConnectionNotFound = errors.NewKind("connection not found: %c")
var ErrRowTimeout = errors.NewKind("row read wait bigger than connection timeout")

// TODO parametrize
const rowsBatch = 100
Expand Down Expand Up @@ -137,7 +137,8 @@ func (h *Handler) ComQuery(
if h.readTimeout > 0 {
waitTime = h.readTimeout
}
timer := time.NewTimer(h.readTimeout)
timer := time.NewTimer(waitTime)
defer timer.Stop()

rowLoop:
for {
Expand Down Expand Up @@ -172,18 +173,16 @@ rowLoop:
r.Rows = append(r.Rows, outputRow)
r.RowsAffected++
case <-timer.C:
if h.readTimeout != 0 && waitTime >= h.readTimeout {
if h.readTimeout != 0 {
// Return so Vitess can call the CloseConnection callback
err = RowTimeout.New()
err = ErrRowTimeout.New()
close(quit)
break rowLoop
}
}
timer.Reset(waitTime)
}

timer.Stop()

if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion server/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func TestHandlerTimeout(t *testing.T) {
err := timeOutHandler.ComQuery(connTimeout, "SELECT SLEEP(2)", func(res *sqltypes.Result) error {
return nil
})
require.EqualError(err, "Row read wait bigger than connection timeout")
require.EqualError(err, "row read wait bigger than connection timeout")

err = timeOutHandler.ComQuery(connTimeout, "SELECT SLEEP(0.5)", func(res *sqltypes.Result) error {
return nil
Expand Down

0 comments on commit 7462152

Please sign in to comment.