Browse Source

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.
s3tables-by-claude
Chris Lu 4 days ago
parent
commit
c106532b79
  1. 6
      weed/command/filer.go
  2. 5
      weed/command/master.go
  3. 3
      weed/command/s3.go
  4. 5
      weed/command/volume.go

6
weed/command/filer.go

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

5
weed/command/master.go

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

3
weed/command/s3.go

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

5
weed/command/volume.go

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

Loading…
Cancel
Save