fix: prevent MiniClusterCtx race conditions in command shutdown

Capture global MiniClusterCtx into local variables before goroutine/select
evaluation to prevent nil dereference/data race when context is reset to nil
after nil check. Applied to filer, master, volume, and s3 commands.
This commit is contained in:
Chris Lu
2026-01-28 19:42:16 -08:00
parent a4217dff5f
commit c106532b79
4 changed files with 12 additions and 7 deletions

View File

@@ -483,8 +483,9 @@ func (fo *FilerOptions) startFiler() {
}
httpS := newHttpServer(defaultMux, tlsConfig)
if MiniClusterCtx != nil {
ctx := MiniClusterCtx
go func() {
<-MiniClusterCtx.Done()
<-ctx.Done()
httpS.Shutdown(context.Background())
grpcS.Stop()
}()
@@ -502,8 +503,9 @@ func (fo *FilerOptions) startFiler() {
}
httpS := newHttpServer(defaultMux, nil)
if MiniClusterCtx != nil {
ctx := MiniClusterCtx
go func() {
<-MiniClusterCtx.Done()
<-ctx.Done()
httpS.Shutdown(context.Background())
grpcS.Stop()
}()

View File

@@ -311,8 +311,9 @@ func startMaster(masterOption MasterOptions, masterWhiteList []string) {
ms.Topo.HashicorpRaft.LeadershipTransfer()
}
})
if MiniClusterCtx != nil {
<-MiniClusterCtx.Done()
ctx := MiniClusterCtx
if ctx != nil {
<-ctx.Done()
ms.Shutdown()
grpcS.Stop()
} else {

View File

@@ -408,8 +408,9 @@ func (s3opt *S3Options) startS3Server() bool {
}
httpS := newHttpServer(router, tlsConfig)
if MiniClusterCtx != nil {
ctx := MiniClusterCtx
go func() {
<-MiniClusterCtx.Done()
<-ctx.Done()
httpS.Shutdown(context.Background())
grpcS.Stop()
}()

View File

@@ -319,10 +319,11 @@ func (v VolumeServerOptions) startVolumeServer(volumeFolders, maxVolumeCounts, v
stopChan <- true
})
if MiniClusterCtx != nil {
ctx := MiniClusterCtx
if ctx != nil {
select {
case <-stopChan:
case <-MiniClusterCtx.Done():
case <-ctx.Done():
shutdown(publicHttpDown, clusterHttpServer, grpcS, volumeServer)
}
} else {