Fix channel closing issues in pipeline stages to prevent panic when running tests
This commit is contained in:
@@ -229,6 +229,12 @@ func TransactionDecoderStage(
|
||||
// Wait for all workers to finish, then close the output channel
|
||||
go func() {
|
||||
wg.Wait()
|
||||
// Use recover to handle potential panic from closing already closed channel
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
// Channel already closed, that's fine
|
||||
}
|
||||
}()
|
||||
close(output)
|
||||
}()
|
||||
|
||||
@@ -317,6 +323,12 @@ func MarketAnalysisStage(
|
||||
// Wait for all workers to finish, then close the output channel
|
||||
go func() {
|
||||
wg.Wait()
|
||||
// Use recover to handle potential panic from closing already closed channel
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
// Channel already closed, that's fine
|
||||
}
|
||||
}()
|
||||
close(output)
|
||||
}()
|
||||
|
||||
@@ -436,6 +448,12 @@ func ArbitrageDetectionStage(
|
||||
// Wait for all workers to finish, then close the output channel
|
||||
go func() {
|
||||
wg.Wait()
|
||||
// Use recover to handle potential panic from closing already closed channel
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
// Channel already closed, that's fine
|
||||
}
|
||||
}()
|
||||
close(output)
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user