File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -695,8 +695,17 @@ func (store *Store) SubHeadChanges(ctx context.Context) chan []*types.HeadChange
695
695
}}
696
696
697
697
go func () {
698
- defer close (out )
699
- var unsubOnce sync.Once
698
+ defer func () {
699
+ // Tell the caller we're done first, the following may block for a bit.
700
+ close (out )
701
+
702
+ // Unsubscribe.
703
+ store .headEvents .Unsub (subCh )
704
+
705
+ // Drain the channel.
706
+ for range subCh {
707
+ }
708
+ }()
700
709
701
710
for {
702
711
select {
@@ -716,9 +725,8 @@ func (store *Store) SubHeadChanges(ctx context.Context) chan []*types.HeadChange
716
725
log .Warnf ("head change sub is slow, has %d buffered entries" , len (out ))
717
726
}
718
727
case <- ctx .Done ():
719
- unsubOnce .Do (func () {
720
- go store .headEvents .Unsub (subCh )
721
- })
728
+ log .Infof ("exit sub head change: %v" , ctx .Err ())
729
+ return
722
730
}
723
731
}
724
732
}()
You can’t perform that action at this time.
0 commit comments