Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

fix: prevent stack overflow in ECBalanceTask.reportProgress (#8949)

Chris Lub0a4647d8798
diff --git a/weed/worker/tasks/ec_balance/ec_balance_task.go b/weed/worker/tasks/ec_balance/ec_balance_task.go
index 2b0729535d..904b6db8e2 100644
--- a/weed/worker/tasks/ec_balance/ec_balance_task.go
+++ b/weed/worker/tasks/ec_balance/ec_balance_task.go
@@ -3,6 +3,8 @@ package ec_balance
import (
"context"
"fmt"
+ "math"
+ "sync/atomic"
"time"
"github.com/seaweedfs/seaweedfs/weed/glog"
@@ -22,7 +24,8 @@ type ECBalanceTask struct {
volumeID uint32
collection string
grpcDialOption grpc.DialOption
- progress float64
+ progress uint64 // atomic; stores float64 bits via math.Float64bits
+ reporting int32 // atomic; re-entry guard to prevent recursive reportProgress calls
}
// NewECBalanceTask creates a new EC balance task instance
@@ -206,12 +209,16 @@ func (t *ECBalanceTask) EstimateTime(params *worker_pb.TaskParams) time.Duration
// GetProgress returns current progress
func (t *ECBalanceTask) GetProgress() float64 {
- return t.progress
+ return math.Float64frombits(atomic.LoadUint64(&t.progress))
}
// reportProgress updates the stored progress and reports it via the callback
func (t *ECBalanceTask) reportProgress(progress float64, stage string) {
- t.progress = progress
+ if !atomic.CompareAndSwapInt32(&t.reporting, 0, 1) {
+ return
+ }
+ defer atomic.StoreInt32(&t.reporting, 0)
+ atomic.StoreUint64(&t.progress, math.Float64bits(progress))
t.ReportProgressWithStage(progress, stage)
glog.Infof("EC balance volume %d: [%.2f] %s", t.volumeID, progress, stage)
}