From 09d37880bafc78b43a429610d8825b095e9f24df Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Thu, 9 Feb 2017 21:42:58 -0600 Subject: [PATCH] wip --- conn-lock-todo.txt | 11 +++++++++++ conn.go | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 conn-lock-todo.txt diff --git a/conn-lock-todo.txt b/conn-lock-todo.txt new file mode 100644 index 00000000..ab5eac95 --- /dev/null +++ b/conn-lock-todo.txt @@ -0,0 +1,11 @@ +Extract all locking state into a separate struct that will encapsulate locking and state change behavior. + +This struct should add or subsume at least the following: +* alive +* closingLock +* ctxInProgress (though this may be restructured because it's possible a Tx may have a ctx and a query run in that Tx could have one) +* busy +* lock/unlock +* Tx in-progress +* Rows in-progress +* ConnPool checked-out or checked-in - maybe include reference to conn pool diff --git a/conn.go b/conn.go index 7ecd18b2..78bdcedc 100644 --- a/conn.go +++ b/conn.go @@ -1403,6 +1403,9 @@ func (c *Conn) termContext(opErr error) error { select { case err = <-c.closedChan: + if dlErr := c.conn.SetDeadline(time.Time{}); dlErr != nil { + c.Close() // Close connection if unable to disable deadline + } if opErr == nil { err = nil } @@ -1418,7 +1421,9 @@ func (c *Conn) contextHandler(ctx context.Context) { select { case <-ctx.Done(): c.cancelQuery() - c.Close() + if err := c.conn.SetDeadline(time.Now()); err != nil { + c.Close() // Close connection if unable to set deadline + } c.closedChan <- ctx.Err() case <-c.doneChan: }