aboutsummaryrefslogtreecommitdiff
path: root/src/database/sql
diff options
context:
space:
mode:
authorEric Rykwalder <e.rykwalder@gmail.com>2018-04-02 22:15:59 -0700
committerDaniel Theophanes <kardianos@gmail.com>2018-04-11 19:45:16 +0000
commit16f32a0726567ddba7627629b7557086058fbe70 (patch)
tree2c88a101be9e1d5874b24ed8e70f622f59dd96e0 /src/database/sql
parent7a7b63f3e749e3608ee16b1807349a778d562c08 (diff)
downloadgo-16f32a0726567ddba7627629b7557086058fbe70.tar.xz
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>
Diffstat (limited to 'src/database/sql')
-rw-r--r--src/database/sql/sql.go5
-rw-r--r--src/database/sql/sql_test.go4
2 files changed, 7 insertions, 2 deletions
diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go
index 355b6aa300..beccf7fec1 100644
--- a/src/database/sql/sql.go
+++ b/src/database/sql/sql.go
@@ -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")
diff --git a/src/database/sql/sql_test.go b/src/database/sql/sql_test.go
index 12cea0de9f..f194744aef 100644
--- a/src/database/sql/sql_test.go
+++ b/src/database/sql/sql_test.go
@@ -325,8 +325,8 @@ func TestQueryContext(t *testing.T) {
}
t.Fatalf("Scan: %v", err)
}
- if index == 2 && err == nil {
- t.Fatal("expected an error on last scan")
+ if index == 2 && err != context.Canceled {
+ t.Fatalf("Scan: %v; want context.Canceled", err)
}
got = append(got, r)
index++