Skip to content

Instantly share code, notes, and snippets.

@dasl-
Created September 18, 2019 15:32
Show Gist options
  • Save dasl-/83f150144d3442bcb92829be2555ab46 to your computer and use it in GitHub Desktop.
Save dasl-/83f150144d3442bcb92829be2555ab46 to your computer and use it in GitHub Desktop.
diff --git a/go/vt/vttablet/tabletserver/connpool/dbconn.go b/go/vt/vttablet/tabletserver/connpool/dbconn.go
index f505dff7d..c15d33878 100644
--- a/go/vt/vttablet/tabletserver/connpool/dbconn.go
+++ b/go/vt/vttablet/tabletserver/connpool/dbconn.go
@@ -123,34 +123,36 @@ func (dbc *DBConn) Exec(ctx context.Context, query string, maxrows int, wantfiel
// Return the error of the reconnect and not the original connection error.
return nil, reconnectErr
}
// Reconnect succeeded. Retry query at second attempt.
}
panic("unreachable")
}
func (dbc *DBConn) execOnce(ctx context.Context, query string, maxrows int, wantfields bool) (*sqltypes.Result, error) {
dbc.current.Set(query)
defer dbc.current.Set("")
// Check if the context is already past its deadline before
// trying to execute the query.
+ start := time.Now()
select {
case <-ctx.Done():
- return nil, fmt.Errorf("%v before execution started", ctx.Err())
- default:
+ elapsed := time.Since(start)
+ return nil, fmt.Errorf("%v before execution started after %s", ctx.Err(), elapsed)
+ case <-time.After(1000 * time.Second):
}
done, wg := dbc.setDeadline(ctx)
if done != nil {
defer func() {
close(done)
wg.Wait()
}()
}
// Uncomment this line for manual testing.
// defer time.Sleep(20 * time.Second)
return dbc.conn.ExecuteFetch(query, maxrows, wantfields)
}
// ExecOnce executes the specified query, but does not retry on connection errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment