diff --git a/server/context.go b/server/context.go index 40dc04897..974f32a85 100644 --- a/server/context.go +++ b/server/context.go @@ -24,7 +24,7 @@ func DefaultSessionBuilder(c *mysql.Conn, addr string) sql.Session { // SessionManager is in charge of creating new sessions for the given // connections and keep track of which sessions are in each connection, so -// they can be cancelled is the connection is closed. +// they can be cancelled if the connection is closed. type SessionManager struct { addr string tracer opentracing.Tracer diff --git a/sql/expression/function/sleep.go b/sql/expression/function/sleep.go index 2c672464b..920b54cb5 100644 --- a/sql/expression/function/sleep.go +++ b/sql/expression/function/sleep.go @@ -1,11 +1,11 @@ package function import ( + "context" "fmt" - "time" - "github.com/src-d/go-mysql-server/sql" "github.com/src-d/go-mysql-server/sql/expression" + "time" ) // Sleep is a function that just waits for the specified number of seconds @@ -37,8 +37,15 @@ func (s *Sleep) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { return nil, err } - time.Sleep(time.Duration(child.(float64)*1000) * time.Millisecond) - return 0, nil + t := time.NewTimer(time.Duration(child.(float64) * 1000) * time.Millisecond) + defer t.Stop() + + select { + case <-ctx.Done(): + return 0, context.Canceled + case <-t.C: + return 0, nil + } } // String implements the Stringer interface.