database/sql: return context errors from Rows.Scan

The previous implementation would return "sql: Rows are closed" for any
context errors, which can be confusing for context timeouts or
cancelations.

Fixes #24431

Change-Id: I884904ec43204c43f4e94e2335b2802aab77a888
Reviewed-on: https://go-review.googlesource.com/104276
Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
Run-TryBot: Daniel Theophanes <kardianos@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Eric Rykwalder 2018-04-02 22:15:59 -07:00 committed by Daniel Theophanes
parent 7a7b63f3e7
commit 16f32a0726
2 changed files with 7 additions and 2 deletions

View file

@ -2870,6 +2870,11 @@ func rowsColumnInfoSetupConnLocked(rowsi driver.Rows) []*ColumnType {
// string inputs parseable by strconv.ParseBool.
func (rs *Rows) Scan(dest ...interface{}) error {
rs.closemu.RLock()
if rs.lasterr != nil && rs.lasterr != io.EOF {
rs.closemu.RUnlock()
return rs.lasterr
}
if rs.closed {
rs.closemu.RUnlock()
return errors.New("sql: Rows are closed")