@@ -10,6 +10,7 @@ import (
1010 "crypto/tls"
1111 "crypto/x509"
1212 "crypto/x509/pkix"
13+ "database/sql/driver"
1314 "encoding/json"
1415 "encoding/pem"
1516 "fmt"
@@ -35,6 +36,7 @@ import (
3536 "github.com/stretchr/testify/assert"
3637 "github.com/stretchr/testify/require"
3738 "go.uber.org/goleak"
39+ "golang.org/x/xerrors"
3840 "gopkg.in/yaml.v3"
3941 "tailscale.com/derp/derphttp"
4042 "tailscale.com/types/key"
@@ -1836,7 +1838,7 @@ func TestServer_Logging_NoParallel(t *testing.T) {
18361838 // fails.
18371839 pty := ptytest .New (t ).Attach (inv )
18381840
1839- clitest . Start (t , inv .WithContext (ctx ))
1841+ startIgnoringPostgresQueryCancel (t , inv .WithContext (ctx ))
18401842
18411843 // Wait for server to listen on HTTP, this is a good
18421844 // starting point for expecting logs.
@@ -1873,7 +1875,7 @@ func TestServer_Logging_NoParallel(t *testing.T) {
18731875 // fails.
18741876 pty := ptytest .New (t ).Attach (inv )
18751877
1876- clitest . Start (t , inv )
1878+ startIgnoringPostgresQueryCancel (t , inv )
18771879
18781880 // Wait for server to listen on HTTP, this is a good
18791881 // starting point for expecting logs.
@@ -2397,6 +2399,13 @@ func startIgnoringPostgresQueryCancel(t *testing.T, inv *serpent.Invocation) {
23972399 if database .IsQueryCanceledError (err ) {
23982400 return
23992401 }
2402+ // specifically when making our initial connection to PostgreSQL, we ping the database.
2403+ // Database driver.Conn instances can return driver.ErrBadConn on ping to remove the connection from the pool.
2404+ // lib/pq does this no matter what the error is, including context.Canceled.
2405+ // c.f. https://pkg.go.dev/database/sql/driver#Pinger
2406+ if xerrors .Is (err , driver .ErrBadConn ) {
2407+ return
2408+ }
24002409 assert .NoError (t , err )
24012410 })
24022411}
0 commit comments