Skip to content

Commit 5f88611

Browse files
committed
Don't close channels as receivers
In many places in the code, a receiver creates a channel, passes it to the sender, and closes it on shutdown. This sometimes results in panics due to sends on a closed channel, because the receiver oftentimes cannot guarantee that the sender has stopped sending. In general, only the sender should close channels, and only if necessary in order to notify the receiver that no more elements are coming. To fix this, we just remove the close statements as they are not needed.
1 parent f2b9d02 commit 5f88611

File tree

5 files changed

+0
-19
lines changed

5 files changed

+0
-19
lines changed

rolling-shutter/keyperimpl/gnosis/keyper.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ func (kpr *Keyper) Start(ctx context.Context, runner service.Runner) error {
7373
kpr.newKeyperSets = make(chan *syncevent.KeyperSet)
7474
kpr.newEonPublicKeys = make(chan keyper.EonPublicKey)
7575
kpr.decryptionTriggerChannel = make(chan *broker.Event[*epochkghandler.DecryptionTrigger])
76-
runner.Defer(func() { close(kpr.newBlocks) })
77-
runner.Defer(func() { close(kpr.newKeyperSets) })
78-
runner.Defer(func() { close(kpr.newEonPublicKeys) })
79-
runner.Defer(func() { close(kpr.decryptionTriggerChannel) })
8076

8177
kpr.latestTriggeredSlot = nil
8278

rolling-shutter/medley/chainsync/syncer/eonpubkey.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ func (s *EonPubKeySyncer) Start(ctx context.Context, runner service.Runner) erro
5656
Context: ctx,
5757
}
5858
s.keyBroadcastCh = make(chan *bindings.KeyBroadcastContractEonKeyBroadcast, channelSize)
59-
runner.Defer(func() {
60-
close(s.keyBroadcastCh)
61-
})
6259
subs, err := s.KeyBroadcast.WatchEonKeyBroadcast(watchOpts, s.keyBroadcastCh)
6360
// FIXME: what to do on subs.Error()
6461
if err != nil {

rolling-shutter/medley/chainsync/syncer/keyperset.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ func (s *KeyperSetSyncer) Start(ctx context.Context, runner service.Runner) erro
6666
}
6767
}
6868
s.keyperAddedCh = make(chan *bindings.KeyperSetManagerKeyperSetAdded, channelSize)
69-
runner.Defer(func() {
70-
close(s.keyperAddedCh)
71-
})
7269
subs, err := s.Contract.WatchKeyperSetAdded(watchOpts, s.keyperAddedCh)
7370
// FIXME: what to do on subs.Error()
7471
if err != nil {

rolling-shutter/medley/chainsync/syncer/shutterstate.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ func (s *ShutterStateSyncer) Start(ctx context.Context, runner service.Runner) e
5555
return err
5656
}
5757
runner.Defer(subs.Unsubscribe)
58-
runner.Defer(func() {
59-
close(s.pausedCh)
60-
})
6158

6259
s.unpausedCh = make(chan *bindings.KeyperSetManagerUnpaused)
6360
subs, err = s.Contract.WatchUnpaused(watchOpts, s.unpausedCh)
@@ -66,9 +63,6 @@ func (s *ShutterStateSyncer) Start(ctx context.Context, runner service.Runner) e
6663
return err
6764
}
6865
runner.Defer(subs.Unsubscribe)
69-
runner.Defer(func() {
70-
close(s.unpausedCh)
71-
})
7266

7367
runner.Go(func() error {
7468
return s.watchPaused(ctx)

rolling-shutter/medley/chainsync/syncer/unsafehead.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ func (s *UnsafeHeadSyncer) Start(ctx context.Context, runner service.Runner) err
3333
return err
3434
}
3535
runner.Defer(subs.Unsubscribe)
36-
runner.Defer(func() {
37-
close(s.newLatestHeadCh)
38-
})
3936
runner.Go(func() error {
4037
return s.watchLatestUnsafeHead(ctx)
4138
})

0 commit comments

Comments
 (0)