Fix race in ExecContext
When the context is cancelled, an interrupt should only be made if the operation is still ongoing.
This commit is contained in:
@@ -134,3 +134,24 @@ func TestShortTimeout(t *testing.T) {
|
||||
t.Fatal(ctx.Err())
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecCancel(t *testing.T) {
|
||||
db, err := sql.Open("sqlite3", ":memory:")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
if _, err = db.Exec("create table foo (id integer primary key)"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for n := 0; n < 100; n++ {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
_, err = db.ExecContext(ctx, "insert into foo (id) values (?)", n)
|
||||
cancel()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user