Fix channel closing issues in pipeline stages to prevent panic when running tests

This commit is contained in:
Krypto Kajun
2025-09-12 19:17:26 -05:00
parent 1113d82499
commit 7dd5b5b692
2 changed files with 18 additions and 11 deletions

View File

@@ -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)
}()