Skip to content

Commit ca12abf

Browse files
committed
fix negative WaitGroup counter panics
1 parent fc82cd3 commit ca12abf

5 files changed

Lines changed: 68 additions & 39 deletions

File tree

  • pkg/coordinator/tasks

pkg/coordinator/tasks/generate_blob_transactions/task.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ func (t *Task) Execute(ctx context.Context) error {
163163
txIndex := t.txIndex
164164
t.txIndex++
165165

166+
if pendingChan != nil {
167+
select {
168+
case <-ctx.Done():
169+
return nil
170+
case pendingChan <- true:
171+
}
172+
}
173+
166174
err := t.generateTransaction(ctx, txIndex, func(tx *ethtypes.Transaction, receipt *ethtypes.Receipt, err error) {
167175
if pendingChan != nil {
168176
<-pendingChan
@@ -179,15 +187,11 @@ func (t *Task) Execute(ctx context.Context) error {
179187
})
180188
if err != nil {
181189
t.logger.Errorf("error generating transaction: %v", err.Error())
182-
} else {
190+
183191
if pendingChan != nil {
184-
select {
185-
case <-ctx.Done():
186-
return nil
187-
case pendingChan <- true:
188-
}
192+
<-pendingChan
189193
}
190-
194+
} else {
191195
perBlockCount++
192196
totalCount++
193197
}

pkg/coordinator/tasks/generate_consolidations/task.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ func (t *Task) Execute(ctx context.Context) error {
139139
accountIdx := t.nextIndex
140140
t.nextIndex++
141141

142+
if pendingChan != nil {
143+
select {
144+
case <-ctx.Done():
145+
return nil
146+
case pendingChan <- true:
147+
}
148+
}
149+
150+
pendingWg.Add(1)
151+
142152
tx, err := t.generateConsolidation(ctx, accountIdx, func(tx *ethtypes.Transaction, receipt *ethtypes.Receipt, err error) {
143153
if pendingChan != nil {
144154
<-pendingChan
@@ -161,17 +171,13 @@ func (t *Task) Execute(ctx context.Context) error {
161171
})
162172
if err != nil {
163173
t.logger.Errorf("error generating consolidation: %v", err.Error())
164-
} else {
174+
165175
if pendingChan != nil {
166-
select {
167-
case <-ctx.Done():
168-
return nil
169-
case pendingChan <- true:
170-
}
176+
<-pendingChan
171177
}
172178

173-
pendingWg.Add(1)
174-
179+
pendingWg.Done()
180+
} else {
175181
t.ctx.SetResult(types.TaskResultSuccess)
176182

177183
perSlotCount++

pkg/coordinator/tasks/generate_deposits/task.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ func (t *Task) Execute(ctx context.Context) error {
148148
accountIdx := t.nextIndex
149149
t.nextIndex++
150150

151+
if pendingChan != nil {
152+
select {
153+
case <-ctx.Done():
154+
return nil
155+
case pendingChan <- true:
156+
}
157+
}
158+
159+
pendingWg.Add(1)
160+
151161
pubkey, tx, err := t.generateDeposit(ctx, accountIdx, func(tx *ethtypes.Transaction, receipt *ethtypes.Receipt, err error) {
152162
if pendingChan != nil {
153163
<-pendingChan
@@ -170,17 +180,13 @@ func (t *Task) Execute(ctx context.Context) error {
170180
})
171181
if err != nil {
172182
t.logger.Errorf("error generating deposit: %v", err.Error())
173-
} else {
183+
174184
if pendingChan != nil {
175-
select {
176-
case <-ctx.Done():
177-
return nil
178-
case pendingChan <- true:
179-
}
185+
<-pendingChan
180186
}
181187

182-
pendingWg.Add(1)
183-
188+
pendingWg.Done()
189+
} else {
184190
t.ctx.SetResult(types.TaskResultSuccess)
185191

186192
perSlotCount++

pkg/coordinator/tasks/generate_eoa_transactions/task.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func (t *Task) LoadConfig() error {
115115
return nil
116116
}
117117

118+
//nolint:gocyclo // ignore
118119
func (t *Task) Execute(ctx context.Context) error {
119120
if t.walletPool != nil {
120121
err := t.walletPool.GetRootWallet().AwaitReady(ctx)
@@ -168,6 +169,16 @@ func (t *Task) Execute(ctx context.Context) error {
168169
txIndex := t.txIndex
169170
t.txIndex++
170171

172+
if pendingChan != nil {
173+
select {
174+
case <-ctx.Done():
175+
return nil
176+
case pendingChan <- true:
177+
}
178+
}
179+
180+
pendingWaitGroup.Add(1)
181+
171182
err := t.generateTransaction(ctx, txIndex, func(tx *ethtypes.Transaction, receipt *ethtypes.Receipt, err error) {
172183
if pendingChan != nil {
173184
<-pendingChan
@@ -196,17 +207,13 @@ func (t *Task) Execute(ctx context.Context) error {
196207
})
197208
if err != nil {
198209
t.logger.Errorf("error generating transaction: %v", err.Error())
199-
} else {
210+
200211
if pendingChan != nil {
201-
select {
202-
case <-ctx.Done():
203-
return nil
204-
case pendingChan <- true:
205-
}
212+
<-pendingChan
206213
}
207214

208-
pendingWaitGroup.Add(1)
209-
215+
pendingWaitGroup.Done()
216+
} else {
210217
perBlockCount++
211218
totalCount++
212219
}

pkg/coordinator/tasks/generate_withdrawal_requests/task.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ func (t *Task) Execute(ctx context.Context) error {
134134
accountIdx := t.nextIndex
135135
t.nextIndex++
136136

137+
if pendingChan != nil {
138+
select {
139+
case <-ctx.Done():
140+
return nil
141+
case pendingChan <- true:
142+
}
143+
}
144+
145+
pendingWg.Add(1)
146+
137147
tx, err := t.generateWithdrawal(ctx, accountIdx, func(tx *ethtypes.Transaction, receipt *ethtypes.Receipt, err error) {
138148
if pendingChan != nil {
139149
<-pendingChan
@@ -156,17 +166,13 @@ func (t *Task) Execute(ctx context.Context) error {
156166
})
157167
if err != nil {
158168
t.logger.Errorf("error generating withdrawal: %v", err.Error())
159-
} else {
169+
160170
if pendingChan != nil {
161-
select {
162-
case <-ctx.Done():
163-
return nil
164-
case pendingChan <- true:
165-
}
171+
<-pendingChan
166172
}
167173

168-
pendingWg.Add(1)
169-
174+
pendingWg.Done()
175+
} else {
170176
t.ctx.SetResult(types.TaskResultSuccess)
171177

172178
perSlotCount++

0 commit comments

Comments
 (0)