<feed xmlns='http://www.w3.org/2005/Atom'>
<title>go/src/database/sql/sql_test.go, branch bench-before</title>
<subtitle>Fork of Go programming language with my patches.</subtitle>
<id>http://git.kilabit.info/go/atom?h=bench-before</id>
<link rel='self' href='http://git.kilabit.info/go/atom?h=bench-before'/>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/'/>
<updated>2023-09-20T18:06:13Z</updated>
<entry>
<title>all: simplify bool conditions</title>
<updated>2023-09-20T18:06:13Z</updated>
<author>
<name>Oleksandr Redko</name>
<email>oleksandr.red+github@gmail.com</email>
</author>
<published>2023-09-06T12:14:28Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=da8f406f069490a14aef878559a6db08f4d53344'/>
<id>urn:sha1:da8f406f069490a14aef878559a6db08f4d53344</id>
<content type='text'>
Change-Id: Id2079f7012392dea8dfe2386bb9fb1ea3f487a4a
Reviewed-on: https://go-review.googlesource.com/c/go/+/526015
Reviewed-by: Matthew Dempsky &lt;mdempsky@google.com&gt;
Auto-Submit: Ian Lance Taylor &lt;iant@google.com&gt;
Reviewed-by: Ian Lance Taylor &lt;iant@google.com&gt;
LUCI-TryBot-Result: Go LUCI &lt;golang-scoped@luci-project-accounts.iam.gserviceaccount.com&gt;
Reviewed-by: qiulaidongfeng &lt;2645477756@qq.com&gt;
</content>
</entry>
<entry>
<title>database/sql: add Null[T]</title>
<updated>2023-08-07T14:26:37Z</updated>
<author>
<name>Inada Naoki</name>
<email>songofacandy@gmail.com</email>
</author>
<published>2023-08-05T16:22:48Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=8a6acecfab2879ba4e26487c99f204ede8b3d935'/>
<id>urn:sha1:8a6acecfab2879ba4e26487c99f204ede8b3d935</id>
<content type='text'>
Generic version of NullString, NullInt64, etc.

Fixes #60370

Change-Id: I166a05a6126e8b8571db5cbb026303bb6551d56b
GitHub-Last-Rev: 3c8d2d5141c36f034d2124e19ee090620363ba24
GitHub-Pull-Request: golang/go#60677
Reviewed-on: https://go-review.googlesource.com/c/go/+/501700
Reviewed-by: Jonathan Amsterdam &lt;jba@google.com&gt;
TryBot-Result: Gopher Robot &lt;gobot@golang.org&gt;
Run-TryBot: Ian Lance Taylor &lt;iant@golang.org&gt;
Reviewed-by: Russ Cox &lt;rsc@golang.org&gt;
</content>
</entry>
<entry>
<title>database/sql: prevent internal context error from being returned from Rows.Err()</title>
<updated>2023-07-05T17:10:36Z</updated>
<author>
<name>zikaeroh</name>
<email>zikaeroh@gmail.com</email>
</author>
<published>2023-06-23T00:09:21Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=cd6676126b7e663e6202e98e2f235fff20d5e858'/>
<id>urn:sha1:cd6676126b7e663e6202e98e2f235fff20d5e858</id>
<content type='text'>
CL 497675 modified Rows such that context errors are propagated through
Rows.Err(). This caused an issue where calling Close meant that an
internal cancellation error would (eventually) be returned from Err:

1. A caller makes a query using a cancellable context.
2. initContextClose sees that either the query context or the
   transaction context can be canceled, so will need to spawn a
   goroutine to capture their errors.
3. initContextClose derives a context from the query context via
   WithCancel and sets rs.cancel.
4. When a user calls Close, rs.cancel is called. awaitDone's ctx is
   cancelled, which is good, since we don't want it to hang forever.
5. This internal cancellation (after CL 497675) has its error saved on
   contextDone.
6. Later, calling Err will return the error in contextDone if present.

This leads to a race condition depending on how quickly Err is called
after Close.

The docs for Close and Err state that calling Close should have no
affect on the return result for Err. So, a potential fix is to ensure
that awaitDone does not save the error when the cancellation comes from
a Close via rs.cancel.

This CL does that, using a new context not derived from the query
context, whose error is ignored as the query context's error used to be
before the original bugfix.

The included test fails before the CL, and passes afterward.

Fixes #60932

Change-Id: I2bf4c549efd83d62b86e298c9c45ebd06a3ad89a
Reviewed-on: https://go-review.googlesource.com/c/go/+/505397
Auto-Submit: Russ Cox &lt;rsc@golang.org&gt;
Run-TryBot: Russ Cox &lt;rsc@golang.org&gt;
TryBot-Result: Gopher Robot &lt;gobot@golang.org&gt;
Reviewed-by: Russ Cox &lt;rsc@golang.org&gt;
Reviewed-by: Dmitri Shuralyov &lt;dmitshur@google.com&gt;
Reviewed-by: Brad Fitzpatrick &lt;bradfitz@golang.org&gt;
</content>
</entry>
<entry>
<title>database/sql: fix flake in TestContextCancelDuringRawBytesScan</title>
<updated>2023-06-13T19:41:21Z</updated>
<author>
<name>Russ Cox</name>
<email>rsc@golang.org</email>
</author>
<published>2023-06-13T18:37:57Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=70cb990b15807eb61351b8fbeac28704240787bd'/>
<id>urn:sha1:70cb990b15807eb61351b8fbeac28704240787bd</id>
<content type='text'>
If the cancellation takes effect between Next and Scan,
then Scan returns context.Canceled, but the test wasn't
allowing this case.

The old flake reproduced easily with:

	go test -c
	stress ./sql.test -test.count=100 -test.run=TestContextCancelDuringRawBytesScan

The new test modes exercise that path directly instead of needing stress.

The new check for context.Canceled fixes the new test mode "top".

Fixes #60445.

Change-Id: I3870039a0fbe0a43c3e261b43b175ef83f818765
Reviewed-on: https://go-review.googlesource.com/c/go/+/502876
Reviewed-by: Ian Lance Taylor &lt;iant@google.com&gt;
TryBot-Result: Gopher Robot &lt;gobot@golang.org&gt;
Reviewed-by: Brad Fitzpatrick &lt;bradfitz@golang.org&gt;
Auto-Submit: Russ Cox &lt;rsc@golang.org&gt;
Run-TryBot: Russ Cox &lt;rsc@golang.org&gt;
</content>
</entry>
<entry>
<title>database/sql: fix regression from earlier RawBytes fix</title>
<updated>2023-05-26T03:06:19Z</updated>
<author>
<name>Brad Fitzpatrick</name>
<email>bradfitz@golang.org</email>
</author>
<published>2023-05-25T21:52:01Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=145eec87683b4f09491bd4c6fc6448b920f4f4f3'/>
<id>urn:sha1:145eec87683b4f09491bd4c6fc6448b920f4f4f3</id>
<content type='text'>
The earlier CL 497675 for #60304 introduced a behavior change
that, while not strictly a bug, caused a bunch of test failures
in a large codebase. Rather than add behavior changes in a 10 year
old package, revert to the old behavior: a context cancelation
between Rows.Next reporting false and a call to Rows.Err should
not result in Rows.Err returning the context error.

That behavior was accidentally added in CL 497675 as part of changing
how contexts and Rows iteration worked.

Updates #60304
Updates #53970

Change-Id: I22f8a6a6b0b5a94b430576cf50e015efd01ec652
Reviewed-on: https://go-review.googlesource.com/c/go/+/498398
Run-TryBot: Brad Fitzpatrick &lt;bradfitz@golang.org&gt;
Reviewed-by: Russ Cox &lt;rsc@golang.org&gt;
Reviewed-by: Ian Lance Taylor &lt;iant@google.com&gt;
TryBot-Result: Gopher Robot &lt;gobot@golang.org&gt;
</content>
</entry>
<entry>
<title>database/sql: make RawBytes safely usable with contexts</title>
<updated>2023-05-24T04:00:19Z</updated>
<author>
<name>Brad Fitzpatrick</name>
<email>bradfitz@golang.org</email>
</author>
<published>2023-05-23T22:12:47Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=298fe517a9333c05143a8a8e1f9d5499f0c6e59b'/>
<id>urn:sha1:298fe517a9333c05143a8a8e1f9d5499f0c6e59b</id>
<content type='text'>
sql.RawBytes was added the very first Go release, Go 1. Its docs
say:

&gt; RawBytes is a byte slice that holds a reference to memory owned by
&gt; the database itself. After a Scan into a RawBytes, the slice is only
&gt; valid until the next call to Next, Scan, or Close.

That "only valid until the next call" bit was true at the time,
until contexts were added to database/sql in Go 1.8.

In the past ~dozen releases it's been unsafe to use QueryContext with
a context that might become Done to get an *sql.Rows that's scanning
into a RawBytes. The Scan can succeed, but then while the caller's
reading the memory, a database/sql-managed goroutine can see the
context becoming done and call Close on the database/sql/driver and
make the caller's view of the RawBytes memory no longer valid,
introducing races, crashes, or database corruption. See #60304
and #53970 for details.

This change does the minimal surgery on database/sql to make it safe
again: Rows.Scan was already acquiring a mutex to check whether the
rows had been closed, so this change make Rows.Scan notice whether
*RawBytes was used and, if so, doesn't release the mutex on exit
before returning. That mean it's still locked while the user code
operates on the RawBytes memory and the concurrent context-watching
goroutine to close the database still runs, but if it fires, it then
gets blocked on the mutex until the next call to a Rows method (Next,
NextResultSet, Err, Close).

Updates #60304
Updates #53970 (earlier one I'd missed)

Change-Id: Ie41c0c6f32c24887b2f53ec3686c2aab73a1bfff
Reviewed-on: https://go-review.googlesource.com/c/go/+/497675
TryBot-Result: Gopher Robot &lt;gobot@golang.org&gt;
Reviewed-by: Ian Lance Taylor &lt;iant@google.com&gt;
Run-TryBot: Brad Fitzpatrick &lt;bradfitz@golang.org&gt;
Auto-Submit: Ian Lance Taylor &lt;iant@google.com&gt;
Reviewed-by: Russ Cox &lt;rsc@golang.org&gt;
</content>
</entry>
<entry>
<title>database/sql: remove a distracting alloc, use atomic.Bool</title>
<updated>2023-03-14T20:34:27Z</updated>
<author>
<name>Brad Fitzpatrick</name>
<email>bradfitz@golang.org</email>
</author>
<published>2023-03-10T17:38:49Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=08c32998297e66486416d4021630510eafdcd81e'/>
<id>urn:sha1:08c32998297e66486416d4021630510eafdcd81e</id>
<content type='text'>
This removes an allocation in Conn.grabConn that, while not super
important, was distracting me when optimizing code elsewhere.

While here, convert an atomic that was forgotten when this package was
earlier updated to use the new Go 1.19 typed atomics.

Change-Id: I4666256b4c0512e2162bd485c389130699f9d5ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/475415
Reviewed-by: David Crawshaw &lt;crawshaw@golang.org&gt;
Reviewed-by: Ian Lance Taylor &lt;iant@google.com&gt;
TryBot-Result: Gopher Robot &lt;gobot@golang.org&gt;
Reviewed-by: Cherry Mui &lt;cherryyz@google.com&gt;
Run-TryBot: Brad Fitzpatrick &lt;bradfitz@golang.org&gt;
</content>
</entry>
<entry>
<title>database/sql: make TestTxContextWaitNoDiscard test more robust</title>
<updated>2022-07-11T17:14:33Z</updated>
<author>
<name>Dmitri Goutnik</name>
<email>dgoutnik@gmail.com</email>
</author>
<published>2022-07-09T12:36:45Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=398dcd1cf00a1536dad98cf87c16f8ad0c8913fc'/>
<id>urn:sha1:398dcd1cf00a1536dad98cf87c16f8ad0c8913fc</id>
<content type='text'>
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 &lt;mknyszek@google.com&gt;
TryBot-Result: Gopher Robot &lt;gobot@golang.org&gt;
Auto-Submit: Bryan Mills &lt;bcmills@google.com&gt;
Run-TryBot: Dmitri Goutnik &lt;dgoutnik@gmail.com&gt;
Reviewed-by: Bryan Mills &lt;bcmills@google.com&gt;
</content>
</entry>
<entry>
<title>database/sql: fix close rows error ignored in Next</title>
<updated>2022-05-19T20:21:12Z</updated>
<author>
<name>Jinzhu</name>
<email>wosmvp@gmail.com</email>
</author>
<published>2022-05-19T02:44:00Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=29057b707d468bd690e6eadfebe89c4ff737867c'/>
<id>urn:sha1:29057b707d468bd690e6eadfebe89c4ff737867c</id>
<content type='text'>
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 &lt;kardianos@gmail.com&gt;
Reviewed-by: Bryan Mills &lt;bcmills@google.com&gt;
Reviewed-by: Michael Knyszek &lt;mknyszek@google.com&gt;
Run-TryBot: Daniel Theophanes &lt;kardianos@gmail.com&gt;
TryBot-Result: Gopher Robot &lt;gobot@golang.org&gt;
</content>
</entry>
<entry>
<title>all: fix spelling</title>
<updated>2022-05-17T19:51:29Z</updated>
<author>
<name>John Bampton</name>
<email>jbampton@gmail.com</email>
</author>
<published>2022-05-17T17:09:28Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=a6f3f8d97306dc77144b6d3be8cf706c11e2de8f'/>
<id>urn:sha1:a6f3f8d97306dc77144b6d3be8cf706c11e2de8f</id>
<content type='text'>
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 &lt;bcmills@google.com&gt;
Reviewed-by: Robert Griesemer &lt;gri@google.com&gt;
TryBot-Result: Gopher Robot &lt;gobot@golang.org&gt;
Run-TryBot: Bryan Mills &lt;bcmills@google.com&gt;
Auto-Submit: Bryan Mills &lt;bcmills@google.com&gt;
</content>
</entry>
</feed>
