@@ -246,18 +246,20 @@ func (api *FilterAPI) NewVotes(ctx context.Context) (*rpc.Subscription, error) {
246246 return & rpc.Subscription {}, rpc .ErrNotificationsUnsupported
247247 }
248248
249- rpcSub := notifier .CreateSubscription ()
249+ var (
250+ rpcSub = notifier .CreateSubscription ()
251+ votes = make (chan * types.VoteEnvelope , 128 )
252+ voteSub = api .events .SubscribeNewVotes (votes )
253+ )
250254
251255 gopool .Submit (func () {
252- votes := make (chan * types.VoteEnvelope , 128 )
253- voteSub := api .events .SubscribeNewVotes (votes )
256+ defer voteSub .Unsubscribe ()
254257
255258 for {
256259 select {
257260 case vote := <- votes :
258261 notifier .Notify (rpcSub .ID , vote )
259262 case <- rpcSub .Err ():
260- voteSub .Unsubscribe ()
261263 return
262264 }
263265 }
@@ -366,18 +368,20 @@ func (api *FilterAPI) NewFinalizedHeaders(ctx context.Context) (*rpc.Subscriptio
366368 return & rpc.Subscription {}, rpc .ErrNotificationsUnsupported
367369 }
368370
369- rpcSub := notifier .CreateSubscription ()
371+ var (
372+ rpcSub = notifier .CreateSubscription ()
373+ headers = make (chan * types.Header )
374+ headersSub = api .events .SubscribeNewFinalizedHeaders (headers )
375+ )
370376
371377 gopool .Submit (func () {
372- headers := make (chan * types.Header )
373- headersSub := api .events .SubscribeNewFinalizedHeaders (headers )
378+ defer headersSub .Unsubscribe ()
374379
375380 for {
376381 select {
377382 case h := <- headers :
378383 notifier .Notify (rpcSub .ID , h )
379384 case <- rpcSub .Err ():
380- headersSub .Unsubscribe ()
381385 return
382386 }
383387 }
0 commit comments