summaryrefslogtreecommitdiff
path: root/src/database/sql
Commit message (Collapse)AuthorAgeFilesLines
* database/sql: make TestTxContextWaitNoDiscard test more robustDmitri Goutnik2022-07-111-30/+15
| | | | | | | | | | | | | | | Similar to CL 385934, rely on waiter trigger instead of the WAIT query prefix and factor out the common test code. Fixes #53222 Change-Id: I46efc85ca102b350bb4dbe8e514921e016870ffb Reviewed-on: https://go-review.googlesource.com/c/go/+/416655 Reviewed-by: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Dmitri Goutnik <dgoutnik@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com>
* database/sql/driver: fix typo in driver.gomstmdev2022-06-041-4/+4
| | | | | | | | | | | | | | | ExecerContext -> ExecContext QueryerContext -> QueryContext Change-Id: Id3b1f44de5aa47372d59696523b4379e1fbfc11c GitHub-Last-Rev: 571d01f8052cef27bd5f91a5e95c0735ddf2e327 GitHub-Pull-Request: golang/go#53235 Reviewed-on: https://go-review.googlesource.com/c/go/+/410415 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* database/sql: fix close rows error ignored in NextJinzhu2022-05-193-1/+39
| | | | | | | | | | | | Change-Id: I19f0d764e2a6122307f3f26a6dd3be7b1155c73b GitHub-Last-Rev: 9f1f883c452201679a2d2af2cc29de0f09a43f28 GitHub-Pull-Request: golang/go#52756 Reviewed-on: https://go-review.googlesource.com/c/go/+/404794 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* all: fix spellingJohn Bampton2022-05-171-1/+1
| | | | | | | | | | | | Change-Id: Iee18987c495d1d4bde9da888d454eea8079d3ebc GitHub-Last-Rev: ff5e01599ddf7deb3ab6ce190ba92eb02ae2cb15 GitHub-Pull-Request: golang/go#52949 Reviewed-on: https://go-review.googlesource.com/c/go/+/406915 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
* all: fix spellingJohn Bampton2022-05-171-1/+1
| | | | | | | | | | | | Change-Id: I68538a50c22b02cdb5aa2a889f9440fed7b94c54 GitHub-Last-Rev: aaac9e78340ac482e9cd1b506a035f271c29648c GitHub-Pull-Request: golang/go#52944 Reviewed-on: https://go-review.googlesource.com/c/go/+/406835 Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
* database/sql: follow convention for field namingJinzhu2022-05-141-3/+2
| | | | | | | | | | | | Change-Id: I161072698dad8f184b46c6e627bbfbcb18a1b5c6 GitHub-Last-Rev: 7c8d2412806e6017e7129a5535adace396e6be30 GitHub-Pull-Request: golang/go#52770 Reviewed-on: https://go-review.googlesource.com/c/go/+/404934 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* all: fix some lint issuesRyan Leung2022-05-081-4/+2
| | | | | | | | | | | | | | | Make some code more simple. Change-Id: I801adf0dba5f6c515681345c732dbb907f945419 GitHub-Last-Rev: a505146baca00a1b3268d11d10510afa8cea6f1d GitHub-Pull-Request: golang/go#49626 Reviewed-on: https://go-review.googlesource.com/c/go/+/364634 Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
* all: gofmt main repoRuss Cox2022-04-114-80/+85
| | | | | | | | | | | | | | | [This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* all: remove trailing blank doc comment linesRuss Cox2022-04-012-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | A future change to gofmt will rewrite // Doc comment. // func f() to // Doc comment. func f() Apply that change preemptively to all doc comments. For #51082. Change-Id: I4023e16cfb0729b64a8590f071cd92f17343081d Reviewed-on: https://go-review.googlesource.com/c/go/+/384259 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* all: fix various doc comment formatting nitsRuss Cox2022-04-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A run of lines that are indented with any number of spaces or tabs format as a <pre> block. This commit fixes various doc comments that format badly according to that (standard) rule. For example, consider: // - List item. // Second line. // - Another item. Because the - lines are unindented, this is actually two paragraphs separated by a one-line <pre> block. This CL rewrites it to: // - List item. // Second line. // - Another item. Today, that will format as a single <pre> block. In a future release, we hope to format it as a bulleted list. Various other minor fixes as well, all in preparation for reformatting. For #51082. Change-Id: I95cf06040d4186830e571cd50148be3bf8daf189 Reviewed-on: https://go-review.googlesource.com/c/go/+/384257 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* database/sql: make WAIT tests more robust, rely on waiter triggerDaniel Theophanes2022-02-162-13/+21
| | | | | | | | | | | | | | Replace the WAIT query prefix with a function callback. This fixes timing issues when the testing on loaded servers. Fixes #51208 Change-Id: I5151b397b7066c27ce6bc02c160dde0b584934bc Reviewed-on: https://go-review.googlesource.com/c/go/+/385934 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Trust: Daniel Theophanes <kardianos@gmail.com>
* database/sql: consolidate test polling loopsBryan C. Mills2022-01-131-50/+61
| | | | | | | | | | | | | Also eliminate some arbitrary deadlines and sleeps. Fixes #49958 Change-Id: I999b39a896e430e3bb93aa8b8c9444f28bbaa9d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/378395 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
* all: gofmt -w -r 'interface{} -> any' srcRuss Cox2021-12-138-124/+124
| | | | | | | | | | | | | | | | | | | | | | | | And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* database/sql: prevent closes slices from assigning to free connPavel2021-11-112-13/+50
| | | | | | | | | | | In function connectionCleanerRunLocked append to closing slice affects db.freeConns and vise versa. Sometimes valid connections are closed and some invalid not. Change-Id: I5282f15be3e549533b7d994b17b2060db3c0e7da GitHub-Last-Rev: b3eb3ab6f49c036519f777fc7189e9507010c166 GitHub-Pull-Request: golang/go#49429 Reviewed-on: https://go-review.googlesource.com/c/go/+/362214 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* database/sql: fix tx.Prepare documentationMostafa Solati2021-11-031-2/+2
| | | | | | | | Fixes: #45978 Change-Id: I3d5ccd621d670f97bb1a642b4e84b6629347a315 Reviewed-on: https://go-review.googlesource.com/c/go/+/339291 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Trust: Cherry Mui <cherryyz@google.com>
* database/sql: use errors.Is when checking ErrBadConnDaniel Theophanes2021-11-034-37/+64
| | | | | | | | | | | | | | | | | | | | When drivers return driver.ErrBadConn, no meaningful information about what the cause of the problem is returned. Ideally the driver.ErrBadConn would be always caught with the retry loop, but this is not always the case. Drivers today must choose between returning a useful error and use the rety logic. This allows supporting both. Fixes #47142 Change-Id: I454573028f041dfdf874eed6c254fb194ccf6d96 Reviewed-on: https://go-review.googlesource.com/c/go/+/333949 Run-TryBot: Ian Lance Taylor <iant@golang.org> Trust: Ian Lance Taylor <iant@golang.org> Trust: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* database/sql: Fix idle connection reuseSteven Hartland2021-11-032-43/+130
| | | | | | | | | | | | | | | | | | | | | | | Fix idle connection reuse so that ConnMaxIdleTime clears down excessive idle connections. This now ensures that db.freeConn is ordered by returnedAt and that connections that have been idle for the shortest period are reused first. In addition connectionCleanerRunLocked updates the next check deadline based on idle and maximum life time information so that we avoid waiting up to double MaxIdleTime to close connections. Corrected the calling timer of connectionCleaner. Fixes #39471 Change-Id: I6d26b3542179ef35aa13e5265a89bc0f08ba7fa1 Reviewed-on: https://go-review.googlesource.com/c/go/+/237337 Reviewed-by: Tamás Gulácsi <tgulacsi78@gmail.com> Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Trust: Ian Lance Taylor <iant@golang.org>
* all: use reflect.{Pointer,PointerTo}Cuong Manh Le2021-10-262-5/+5
| | | | | | | | | | | | Updates #47651 Updates #48665 Change-Id: I69a87b45a5cad7a07fbd855040cd9935cf874554 Reviewed-on: https://go-review.googlesource.com/c/go/+/358454 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* all: remove some unused codeAlexander Melentyev2021-09-141-3/+0
| | | | | | | | | | | Change-Id: I519b8021fa79dccc5c0ee79134547491116fc4cc GitHub-Last-Rev: 48869f5434c1255d33c3a14714747509235c94df GitHub-Pull-Request: golang/go#48071 Reviewed-on: https://go-review.googlesource.com/c/go/+/346231 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Keith Randall <khr@golang.org>
* database/sql: improve the documentation of Conn.Rawkorzhao2021-09-041-2/+2
| | | | | | | | | | | Fixes #47500 Change-Id: Ibd44e4db15ea45bb53a6651a6567edfe6104d3d6 GitHub-Last-Rev: 61b8abbc28908fc807af7188e19089ac454b4817 GitHub-Pull-Request: golang/go#47503 Reviewed-on: https://go-review.googlesource.com/c/go/+/338970 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Trust: Cherry Mui <cherryyz@google.com>
* database/sql: fix deadlock test in prepare statementDaniel Theophanes2021-06-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | The issue go#46783 correctly diagnosed the context timeout caused an intermittent failure when the context was canceled prior to the BeginTx call. However due to the asynchronous nature of canceling a Tx through a context on fast systems, the tx.Prepare also succeeded. On slower systems or if a time.Sleep was inserted between the BeginTx and Prepare, the Prepare would fail. Resolve this by moving the context cancel after the Prepare. This will still trigger the deadlock which I tested locally. In addition, I interspersed multiple time.Sleep calls and the test still functioned. Fixes #46852 Change-Id: I9cbf90d3c12b2555493a37799738772b615ae39d Reviewed-on: https://go-review.googlesource.com/c/go/+/329830 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Bryan C. Mills <bcmills@google.com>
* database/sql: do not rely on timeout for deadlock testDaniel Theophanes2021-06-191-1/+2
| | | | | | | | | | | Fixes #46783 Change-Id: I8a8d1716279a041a7411c0c47a440a7997b39c80 Reviewed-on: https://go-review.googlesource.com/c/go/+/328649 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Trust: Carlos Amedee <carlos@golang.org>
* database/sql: add NullInt16 and NullByteAriel Mashraki2021-05-043-1/+85
| | | | | | | | | | | Fixes #40082 Change-Id: I01cd4d0e23c0376a6ee6e0b196c9f840cd662325 Reviewed-on: https://go-review.googlesource.com/c/go/+/311572 Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org>
* all: fix spellingsNaman Gera2021-04-102-3/+3
| | | | | | | | | | | | | | This follows the spelling choices that the Go project has made for English words. https://github.com/golang/go/wiki/Spelling Change-Id: Ie7c586d2cf23020cb492cfff58c0831d2d8d3a78 GitHub-Last-Rev: e16a32cd225a275f73d236bcb33703986d110ded GitHub-Pull-Request: golang/go#45442 Reviewed-on: https://go-review.googlesource.com/c/go/+/308291 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
* database/sql: remove unnecessary types in composite literalsElias5062021-03-251-3/+3
| | | | | | | | | Change-Id: I30c576f826c82cbc62ce28ea7f4886702bd6605d GitHub-Last-Rev: 2fead200dba13ec74d81e842d8bae97d1e67fcc4 GitHub-Pull-Request: golang/go#42618 Reviewed-on: https://go-review.googlesource.com/c/go/+/270000 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Trust: Cherry Zhang <cherryyz@google.com>
* docs: clarify when APIs use context.Background.Matt T. Proud2021-03-111-0/+42
| | | | | | | | | | | | | | | | | | | | | | | The Go standard library retrofitted context support onto existing APIs using context.Background and later offered variants that directly supported user-defined context value specification. This commit makes that behavior clear in documentation and suggests context-aware alternatives if the user is looking for one. An example motivation is supporting code for use in systems that expect APIs to be cancelable for lifecycle correctness or load shedding/management reasons, as alluded to in https://blog.golang.org/context-and-structs. Updates #44143 Change-Id: I2d7f954ddf9b48264d5ebc8d0007058ff9bddf14 Reviewed-on: https://go-review.googlesource.com/c/go/+/296152 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Jean de Klerk <deklerk@google.com> Trust: Jean de Klerk <deklerk@google.com> Run-TryBot: Jean de Klerk <deklerk@google.com> TryBot-Result: Go Bot <gobot@golang.org>
* database/sql: close driver.Connector if it implements io.CloserIvan Trubach2021-02-254-1/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change allows driver implementations to manage resources in driver.Connector, e.g. to share the same underlying database handle between multiple connections. That is, it allows embedded databases with in-memory backends like SQLite and Genji to safely release the resources once the sql.DB is closed. This makes it possible to address oddities with in-memory stores in SQLite and Genji drivers without introducing too much complexity in the driver implementations. See also: - https://github.com/mattn/go-sqlite3/issues/204 - https://github.com/mattn/go-sqlite3/issues/511 - https://github.com/genjidb/genji/issues/210 Fixes #41790 Change-Id: Idbd19763134438ed38288b9d44f16608e4e97fd7 GitHub-Last-Rev: 962c785dfb3bb6ad98b2216bcedd84ba383fe872 GitHub-Pull-Request: golang/go#41710 Reviewed-on: https://go-review.googlesource.com/c/go/+/258360 Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Trust: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org>
* database: remove race in TestTxContextWaitJosh Bleecher Snyder2021-02-241-8/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This test contained a data race. On line 437, db.BeginTx starts a goroutine that runs tx.awaitDone, which reads tx.keepConnOnRollback. On line 445, the test writes to tx.keepConnOnRollback. tx.awaitDone waits on ctx, but because ctx is timeout-based, there's no ordering guarantee between the write and the read. The race detector never caught this before because the context package implementation of Done contained enough synchronization to make it safe. That synchronization is not package of the context API or guarantees, and the first several releases it was not present. Another commit soon will remove that synchronization, exposing the latent data race. To fix the race, emulate a time-based context using an explicit cancellation-based context. This gives us enough control to avoid the race. Change-Id: I103fe9b987b1d4c02e7a20ac3c22a682652128b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/288493 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
* database/sql: fix typo in commentHein Khant Zaw2020-12-101-1/+1
| | | | | | | | | | | Fixes #43116 Change-Id: Ib04fab6ae03f322aa1508ec00523f628d891247a GitHub-Last-Rev: 0a86e665b2c320e0b2aef75ee53bd7281b19b013 GitHub-Pull-Request: golang/go#43122 Reviewed-on: https://go-review.googlesource.com/c/go/+/276992 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
* database/sql, runtime: correct *.Fatal inside goroutines in testsEmmanuel T Odeke2020-10-311-5/+15
| | | | | | | | | | Found by go vet pass "testinggoroutines". Change-Id: I6360af2079617b7aa62dcb9bd7254578ca5d1c1d Reviewed-on: https://go-review.googlesource.com/c/go/+/235527 Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
* database/sql: fix TestTxStmtDeadlock testTzu-Chiao Yeh2020-10-291-4/+2
| | | | | | | | | | | | | | | | Drop error check because errors can be not only ErrTxDone for tx stmt executions, and the purpose of the test is just reproducing deadlock. Fixes #42259 Change-Id: I9e7105ada1403ec7064dcc1c3385b36893a1c195 Reviewed-on: https://go-review.googlesource.com/c/go/+/266097 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Trust: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org>
* database/sql: fix tx stmt deadlock when rollbackTzu-Chiao Yeh2020-10-282-7/+37
| | | | | | | | | | | | | | | | | | | | Tx acquires tx.closemu W-lock and then acquires stmt.closemu.W-lock to fully close the transaction and associated prepared statement. Stmt query and execution run in reverse ways - acquires stmt.closemu.R-lock and then acquires tx.closemu.R-lock to grab tx connection, which may cause deadlock. Prevent the lock is held around tx.closePrepared to ensure no deadlock happens. Fixes #40985 Change-Id: If53909822b87bce11861a6e3035ecb9476d2cd17 Reviewed-on: https://go-review.googlesource.com/c/go/+/250178 Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
* database/sql: fix comment on DB.stop()Ayzat Sadykov2020-10-271-1/+1
| | | | | | | | | | | | Previously, 2 goroutines were created in OpenDB and a comment in the DB.close() field indicated that they were canceled. Later, session Resetter () was removed, but the comment remained the same. This commit just fixes this message Change-Id: Ie81026f51d7770e9cf8004818154021f626fb2e8 GitHub-Last-Rev: 38b338a0d1cd713d71fa547aa842d395e6d75484 GitHub-Pull-Request: golang/go#42191 Reviewed-on: https://go-review.googlesource.com/c/go/+/264838 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Trust: Brad Fitzpatrick <bradfitz@golang.org>
* database/sql: shortestIdleTimeLocked correct min comparisonShinnosuke Sawada2020-08-291-0/+7
| | | | | | | | | | | | | When zero or less, maxIdleTime and maxLifetime means unlimited. Helper function shortestIdleTimeLocked must not return the minimum of the two until both are verified to be greater then zero. Fixes #40841 Change-Id: I1130332baf4ad259cd90c10f4221f5def8510655 Reviewed-on: https://go-review.googlesource.com/c/go/+/248817 Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
* database/sql: make Rows.Scan properly wrap underlying errorsTim Möhlmann2020-08-142-1/+39
| | | | | | | | | | | | | | | | | | The prior implementation used the format verb %v which unfortunately improperly wrapped any underlying scanner errors, and we couldn't use errors.Is nor errors.As. This change fixes that by using the %w verb. Added a unit to ensure that both error sub string matching works, but also that errors.Is works as expected. Fixes #38099 Change-Id: Iea667041dd8081d961246f77f2542330417292dc Reviewed-on: https://go-review.googlesource.com/c/go/+/248337 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql/driver: use correct method name "Connect" in DriverContext docsBrad Erickson2020-05-301-1/+1
| | | | | | | | | Change-Id: I755fedebb1f8f4d3f27b2b3f8626bca03bd36c88 GitHub-Last-Rev: 4a123572d55ad3b0104d3e6501eef5b2f37af4cd GitHub-Pull-Request: golang/go#39305 Reviewed-on: https://go-review.googlesource.com/c/go/+/235518 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
* database/sql: form a complete sentence in code commentKevin Burke2020-05-081-2/+3
| | | | | | Change-Id: Ib6d0f81b5f64473f9ee6be26a08d5102e8edadc4 Reviewed-on: https://go-review.googlesource.com/c/go/+/229477 Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
* database/sql: document Connect and Close may need a timeoutDaniel Theophanes2020-04-281-1/+9
| | | | | | | | | | | | | | | Opening a connection with Connect should still create a derived context with a timeout because some clients will not use a timeout and the connection pool may open a connection asynchronously. Likewise, if a connection close makes a network operation it should provide some type of sane timeout for the operation. Fixes #38185 Change-Id: I9b7ce2996c81c486170dcc84b12672a99610fa27 Reviewed-on: https://go-review.googlesource.com/c/go/+/230438 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
* database/sql: fix incorrect function name in example_testVivian Liang2020-04-281-1/+1
| | | | | | | | | | fixes incorrect function name prefix in `example_test.go` Change-Id: I0cce8afc89f6ee6dab3e5152246d28deb597fe53 GitHub-Last-Rev: 4e9a6067c8307e049ace2e35414a838bf6c8a8a4 GitHub-Pull-Request: golang/go#38715 Reviewed-on: https://go-review.googlesource.com/c/go/+/230381 Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
* database/sql/driver: enhance driver package documentationDaniel Theophanes2020-04-271-0/+29
| | | | | | Change-Id: I455acdb71354f14e0bc4104cbd7abd5c89958dd9 Reviewed-on: https://go-review.googlesource.com/c/go/+/230214 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
* database/sql: de-flake TestTxCannotCommitAfterRollbackDaniel Theophanes2020-04-222-1/+12
| | | | | | | | | | | | | Do not cancel rows during test. Only cancel the Tx. Correct the referenced issue number on the test. Fixes #38597 Change-Id: I0e8ba1bf2a8ba638d121c9c6938501fec1d5e961 Reviewed-on: https://go-review.googlesource.com/c/go/+/229478 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* database/sql: count connections expired in foreground with MaxLifetimeClosedColin2020-04-221-2/+8
| | | | | | | | | | | | | | | | | | | Previously the connection pool would only count connections expired in the background connectionCleaner goroutine towards the MaxLifetimeClosed stat. This change increments the stat correctly when checking for expiry in when acquiring and releasing a connection. Fixes #38058 Change-Id: Id707ddd40a42a4c38658d5f2931da131647d6c29 GitHub-Last-Rev: 0f205ede439efa355a628b6112450f2ca9ced005 GitHub-Pull-Request: golang/go#38263 Reviewed-on: https://go-review.googlesource.com/c/go/+/227278 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
* database/sql: on Tx rollback, retain connection if driver can reset sessionDaniel Theophanes2020-04-202-7/+50
| | | | | | | | | | | | Previously the Tx would drop the connection after rolling back from a context cancel. Now if the driver can reset the session, keep the connection. Change-Id: Ie6a3124275632787629844d91a06bb2e70cc060b Reviewed-on: https://go-review.googlesource.com/c/go/+/216241 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: prevent Tx statement from committing after rollbackDaniel Theophanes2020-04-203-12/+136
| | | | | | | | | | | | | | | | | | It was possible for a Tx that was aborted for rollback asynchronously to execute a query after the rollback had completed on the database, which often would auto commit the query outside of the transaction. By W-locking the tx.closemu prior to issuing the rollback connection it ensures any Tx query either fails or finishes on the Tx, and never after the Tx has rolled back. Fixes #34775 Fixes #32942 Change-Id: I017b7932082f2f4ead70bae08b61ed9068ac1d01 Reviewed-on: https://go-review.googlesource.com/c/go/+/216240 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
* database/sql: check conn expiry when returning to pool, not when handing it outDaniel Theophanes2020-04-202-1/+101
| | | | | | | | | | | | | | | | | | | | | | | With the original connection reuse strategy, it was possible that when a new connection was requested, the pool would wait for an an existing connection to return for re-use in a full connection pool, and then it would check if the returned connection was expired. If the returned connection expired while awaiting re-use, it would return an error to the location requestiong the new connection. The existing call sites requesting a new connection was often the last attempt at returning a connection for a query. This would then result in a failed query. This change ensures that we perform the expiry check right before a connection is inserted back in to the connection pool for while requesting a new connection. If requesting a new connection it will no longer fail due to the connection expiring. Fixes #32530 Change-Id: If16379befe0e14d90160219c0c9396243fe062f7 Reviewed-on: https://go-review.googlesource.com/c/go/+/216197 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
* database/sql: add test for Conn.Validator interfaceDaniel Theophanes2020-03-294-8/+39
| | | | | | | | | | | This addresses comments made by Russ after https://golang.org/cl/174122 was merged. It addes a test for the connection validator and renames the interface to just "Validator". Change-Id: Iea53e9b250c9be2e86e9b75906e7353e26437c5c Reviewed-on: https://go-review.googlesource.com/c/go/+/223963 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
* database/sql: add method Err on sql.RowTim Möhlmann2020-03-192-0/+26
| | | | | | | | | | | | | | | | | The Row.Err method is intended to assist wrapping sql.DB. Because sql.Row is a struct with private fields, a wrapper in an existing code base cannot easily provide users with a different implementation without large rewrites. Adding this method allows query level errors to be handled centrally. Fixes #35804 Change-Id: I94e6329de89a7ee1284ce9ef76af4363d2d081f9 Reviewed-on: https://go-review.googlesource.com/c/go/+/214317 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: fix variable name in exampleHarmen2020-03-181-1/+1
| | | | | | | | | | It's a very minor error, but it's a bad copy/paste example. Change-Id: Ia6a723c31f2205c933857ce2cf715bddf773ebb6 GitHub-Last-Rev: 7f14b1a5c1ea3775aa2009184b0b1790e03225eb GitHub-Pull-Request: golang/go#37932 Reviewed-on: https://go-review.googlesource.com/c/go/+/223960 Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
* database/sql: process all Session Resets synchronouslyDaniel Theophanes2020-03-173-78/+63
| | | | | | | | | | | | | | | | | | | | | | Adds a new interface, driver.ConnectionValidator, to allow drivers to signal they should not be used again, separatly from the session resetter interface. This is done now that the session reset is done after the connection is put into the connection pool. Previous behavior attempted to run Session Resets in a background worker. This implementation had two problems: untested performance gains for additional complexity, and failures when the pool size exceeded the connection reset channel buffer size. Fixes #31480 Change-Id: I7d483b883c24a362c292471e87a88db5b204d1d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/174122 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
* database/sql: add SetConnMaxIdleTimeDaniel Theophanes2020-02-212-31/+149
| | | | | | | | | | | | | | Allow removing a connection from the connection pool after it has been idle for a period of time, without regard to the total lifespan of the connection. Fixes #25232 Change-Id: Icff157b906769a2d2d45c67525e04a72feb8d832 Reviewed-on: https://go-review.googlesource.com/c/go/+/145758 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>