No need to fetch statement duration more than once

This commit is contained in:
Tobie Morgan Hitchcock 2020-03-07 09:55:25 +00:00
parent 2ef562de06
commit f3ab0596f5

View file

@ -269,11 +269,11 @@ func (e *executor) operate(ctx context.Context, stm sql.Statement) (res []interf
// it runs no longer than specified. // it runs no longer than specified.
if stm, ok := stm.(sql.KillableStatement); ok { if stm, ok := stm.(sql.KillableStatement); ok {
if stm.Duration() > 0 { if dur := stm.Duration(); dur > 0 {
ctx, canc = context.WithTimeout(ctx, stm.Duration()) ctx, canc = context.WithTimeout(ctx, dur)
defer func() { defer func() {
if tim := ctx.Err(); err == nil && tim != nil { if tim := ctx.Err(); err == nil && tim != nil {
res, err = nil, &TimerError{timer: stm.Duration()} res, err = nil, &TimerError{timer: dur}
} }
canc() canc()
}() }()