Skip to content

Commit e514d1f

Browse files
fix(load): prevent busy loop and optimize buffer allocation (#552)
1 parent 462382d commit e514d1f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pkg/check/load/load.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ func (c *Check) run(ctx context.Context, cluster orchestration.Cluster, o Option
131131
}
132132
}
133133

134+
txData := make([]byte, contentSize)
135+
134136
for i := 0; true; i++ {
135137
select {
136138
case <-ctx.Done():
@@ -144,11 +146,9 @@ func (c *Check) run(ctx context.Context, cluster orchestration.Cluster, o Option
144146

145147
var (
146148
txDuration time.Duration
147-
txData []byte
148149
address swarm.Address
149150
)
150151

151-
txData = make([]byte, contentSize)
152152
if _, err := crand.Read(txData); err != nil {
153153
c.logger.Infof("unable to create random content for size %d: %v", contentSize, err)
154154
continue
@@ -196,7 +196,9 @@ func (c *Check) run(ctx context.Context, cluster orchestration.Cluster, o Option
196196
batchID, err := uploader.GetOrCreateMutableBatch(ctx, o.PostageTTL, o.PostageDepth, o.PostageLabel)
197197
if err != nil {
198198
c.logger.Errorf("create new batch failed: %v", err)
199-
return
199+
c.logger.Infof("retrying in: %v", o.TxOnErrWait)
200+
time.Sleep(o.TxOnErrWait)
201+
continue
200202
}
201203

202204
c.logger.WithField("batch_id", batchID).Infof("node %s: using batch", uploader.Name())
@@ -217,6 +219,8 @@ func (c *Check) run(ctx context.Context, cluster orchestration.Cluster, o Option
217219
upload.Wait()
218220

219221
if txDuration == 0 {
222+
c.logger.Info("no successful uploads in this iteration, waiting before retrying")
223+
time.Sleep(o.NodesSyncWait)
220224
continue
221225
}
222226

0 commit comments

Comments
 (0)