Skip to content

Commit 9927457

Browse files
authored
Merge pull request #926 from lib/ping-empty
allow ping during a failed txn
2 parents d7918e3 + e3ef896 commit 9927457

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

conn_go18.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (cn *conn) Ping(ctx context.Context) error {
7979
if finish := cn.watchCancel(ctx); finish != nil {
8080
defer finish()
8181
}
82-
rows, err := cn.simpleQuery("SELECT 'lib/pq ping test';")
82+
rows, err := cn.simpleQuery(";")
8383
if err != nil {
8484
return driver.ErrBadConn // https://golang.org/pkg/database/sql/driver/#Pinger
8585
}

go19_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ func TestPing(t *testing.T) {
5555
if rows.Err() != nil {
5656
t.Fatal(err)
5757
}
58+
// Fail the transaction and make sure we can still ping.
59+
if _, err := tx.Query("INVALID SQL"); err == nil {
60+
t.Fatal("expected error")
61+
}
62+
if err := conn.PingContext(ctx); err != nil {
63+
t.Fatal(err)
64+
}
5865
if err := tx.Rollback(); err != nil {
5966
t.Fatal(err)
6067
}

0 commit comments

Comments
 (0)