Skip to content

Commit

Permalink
add watchCancelDialContextTimeout const and notate why we have watchC…
Browse files Browse the repository at this point in the history
…ancel on stmt
  • Loading branch information
Michael Hobbs committed Aug 19, 2021
1 parent b5ce7c4 commit 200830e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions conn_go18.go
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{})
Expand All @@ -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)
Expand Down

0 comments on commit 200830e

Please sign in to comment.