Skip to content

Commit 65cc261

Browse files
craig[bot]jeffswenson
andcommitted
106549: sqlproxyccl: deflake TestDirectoryConnect r=JeffSwenson a=JeffSwenson This contains fixes to two sources of flakes in TestDirectoryConnect: - sqlproxy http draining is now tied into the stopper. This avoids a source of goroutine leaks. - The sql server is gracefully drained to work around cockroachdb#106537. When combined with cockroachdb#106599, I was able to run the test for 25K interations under stress with no flakes. Fixes: cockroachdb#105402 Co-authored-by: Jeff <[email protected]>
2 parents 7d6600e + 55745a8 commit 65cc261

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

pkg/ccl/sqlproxyccl/proxy_handler_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,13 +1389,17 @@ func TestDirectoryConnect(t *testing.T) {
13891389
})
13901390
})
13911391

1392+
// Drain the tenant server gracefully. This is a workaround for #106537.
1393+
// Draining the server allows the server to delete the sql instance row.
1394+
require.NoError(t, tenants[0].DrainClients(ctx))
1395+
13921396
// Stop the directory server and the tenant SQL process started earlier.
13931397
// This tests whether the proxy can recover when the directory server and
13941398
// SQL pod restarts.
13951399
tds.Stop(ctx)
13961400
tenantStopper.Stop(ctx)
13971401

1398-
// Drain old pod and add a new one before starting the directory server.
1402+
// Drain the old pod and add a new one before starting the directory server.
13991403
tds.DrainPod(tenantID, tenants[0].SQLAddr())
14001404
tenants = startTestTenantPods(ctx, t, s, tenantID, 1, base.TestingKnobs{})
14011405
tds.AddPod(tenantID, &tenant.Pod{
@@ -1407,15 +1411,14 @@ func TestDirectoryConnect(t *testing.T) {
14071411
require.NoError(t, tds.Start(ctx))
14081412

14091413
t.Run("successful connection after restart", func(t *testing.T) {
1410-
require.Eventually(t, func() bool {
1414+
testutils.SucceedsSoon(t, func() error {
14111415
conn, err := pgx.Connect(ctx, connectionString)
14121416
if err != nil {
1413-
return false
1417+
return err
14141418
}
14151419
defer func() { _ = conn.Close(ctx) }()
1416-
require.NoError(t, runTestQuery(ctx, conn))
1417-
return true
1418-
}, 30*time.Second, 100*time.Millisecond)
1420+
return runTestQuery(ctx, conn)
1421+
})
14191422
})
14201423
}
14211424

pkg/ccl/sqlproxyccl/server.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func (s *Server) ServeHTTP(ctx context.Context, ln net.Listener) error {
181181

182182
srv := http.Server{Handler: s.mux}
183183

184-
go func() {
184+
err := s.Stopper.RunAsyncTask(ctx, "sqlproxy-http-cleanup", func(ctx context.Context) {
185185
<-ctx.Done()
186186

187187
// Wait up to 15 seconds for the HTTP server to shut itself
@@ -196,11 +196,13 @@ func (s *Server) ServeHTTP(ctx context.Context, ln net.Listener) error {
196196
// Ignore any errors as this routine will only be called
197197
// when the server is shutting down.
198198
_ = srv.Shutdown(shutdownCtx)
199-
200199
return nil
201200
},
202201
)
203-
}()
202+
})
203+
if err != nil {
204+
return err
205+
}
204206

205207
if err := srv.Serve(ln); err != nil && !errors.Is(err, http.ErrServerClosed) {
206208
return err

0 commit comments

Comments
 (0)