diff --git a/cmd/chain-receipts/main.go b/cmd/chain-receipts/main.go index 56e18728..81fd8ef5 100644 --- a/cmd/chain-receipts/main.go +++ b/cmd/chain-receipts/main.go @@ -154,9 +154,7 @@ func listener(provider *ethrpc.Provider, monitorOptions ethmonitor.Options, rece ) var wg sync.WaitGroup - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { for { select { case receipt := <-sub.TransactionReceipt(): @@ -187,7 +185,7 @@ func listener(provider *ethrpc.Provider, monitorOptions ethmonitor.Options, rece return } } - }() + }) wg.Wait() diff --git a/cmd/chain-watch/main.go b/cmd/chain-watch/main.go index 12dc2cae..406d10f2 100644 --- a/cmd/chain-watch/main.go +++ b/cmd/chain-watch/main.go @@ -178,9 +178,7 @@ func chainWatch(provider *ethrpc.Provider, monitorOptions ethmonitor.Options) (* count := 0 var wg sync.WaitGroup - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { for { select { case blocks := <-sub.Blocks(): @@ -210,7 +208,7 @@ func chainWatch(provider *ethrpc.Provider, monitorOptions ethmonitor.Options) (* return } } - }() + }) // TODO: we can implement a program, chain-watch-test // which will assert ethmonitor behaviour diff --git a/ethreceipts/ethreceipts.go b/ethreceipts/ethreceipts.go index cd7854f0..6f7e3557 100644 --- a/ethreceipts/ethreceipts.go +++ b/ethreceipts/ethreceipts.go @@ -358,9 +358,7 @@ func (l *ReceiptsListener) FetchTransactionReceiptWithFilter(ctx context.Context // TODO/NOTE: perhaps in an extended node failure. could there be a scenario // where filterer.Exhausted is never hit? and this subscription never unsubscribes..? // don't think so, but we can double check. - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { defer sub.Unsubscribe() defer close(mined) defer close(finalized) @@ -433,7 +431,7 @@ func (l *ReceiptsListener) FetchTransactionReceiptWithFilter(ctx context.Context } } } - }() + }) // Wait for the first mined receipt or an exit signal select { diff --git a/ethreceipts/ethreceipts_test.go b/ethreceipts/ethreceipts_test.go index 9c508a4e..227d79ce 100644 --- a/ethreceipts/ethreceipts_test.go +++ b/ethreceipts/ethreceipts_test.go @@ -742,15 +742,13 @@ func TestFiltersAddDeadlock(t *testing.T) { // Now try to access the subscriber's filters from another goroutine // This should deadlock if AddFilter is stuck holding the lock - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { time.Sleep(100 * time.Millisecond) // This will try to acquire s.mu.Lock() filters := sub.Filters() t.Logf("Got %d filters", len(filters)) - }() + }) done := make(chan struct{}) go func() {