From 200830e44477149a8b9e8ee329aa22fbaa84b82b Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 18 Aug 2021 20:17:26 -0700 Subject: [PATCH] add watchCancelDialContextTimeout const and notate why we have watchCancel on stmt --- conn_go18.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/conn_go18.go b/conn_go18.go index dda7dc60..3c83082b 100644 --- a/conn_go18.go +++ b/conn_go18.go @@ -11,6 +11,10 @@ import ( "time" ) +const ( + watchCancelDialContextTimeout = time.Second * 10 +) + // Implement the "QueryerContext" interface func (cn *conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) { list := make([]driver.Value, len(args)) @@ -117,7 +121,7 @@ func (cn *conn) watchCancel(ctx context.Context) func() { // so it must not be used for the additional network // request to cancel the query. // Create a new context to pass into the dial. - ctxCancel, cancel := context.WithTimeout(context.Background(), time.Second*10) + ctxCancel, cancel := context.WithTimeout(context.Background(), watchCancelDialContextTimeout) defer cancel() _ = cn.cancel(ctxCancel) @@ -213,6 +217,7 @@ func (st *stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driv return st.Exec(list) } +// watchCancel is implemented on stmt in order to not mark the parent conn as bad func (st *stmt) watchCancel(ctx context.Context) func() { if done := ctx.Done(); done != nil { finished := make(chan struct{}) @@ -223,7 +228,7 @@ func (st *stmt) watchCancel(ctx context.Context) func() { // so it must not be used for the additional network // request to cancel the query. // Create a new context to pass into the dial. - ctxCancel, cancel := context.WithTimeout(context.Background(), time.Second*10) + ctxCancel, cancel := context.WithTimeout(context.Background(), watchCancelDialContextTimeout) defer cancel() _ = st.cancel(ctxCancel)