@@ -159,6 +159,8 @@ func (api *FilterAPI) NewPendingTransactions(ctx context.Context, fullTx *bool)
159159 go func () {
160160 txs := make (chan []* types.Transaction , 128 )
161161 pendingTxSub := api .events .SubscribePendingTxs (txs )
162+ defer pendingTxSub .Unsubscribe ()
163+
162164 chainConfig := api .sys .backend .ChainConfig ()
163165
164166 for {
@@ -176,10 +178,8 @@ func (api *FilterAPI) NewPendingTransactions(ctx context.Context, fullTx *bool)
176178 }
177179 }
178180 case <- rpcSub .Err ():
179- pendingTxSub .Unsubscribe ()
180181 return
181182 case <- notifier .Closed ():
182- pendingTxSub .Unsubscribe ()
183183 return
184184 }
185185 }
@@ -233,16 +233,15 @@ func (api *FilterAPI) NewHeads(ctx context.Context) (*rpc.Subscription, error) {
233233 go func () {
234234 headers := make (chan * types.Header )
235235 headersSub := api .events .SubscribeNewHeads (headers )
236+ defer headersSub .Unsubscribe ()
236237
237238 for {
238239 select {
239240 case h := <- headers :
240241 notifier .Notify (rpcSub .ID , h )
241242 case <- rpcSub .Err ():
242- headersSub .Unsubscribe ()
243243 return
244244 case <- notifier .Closed ():
245- headersSub .Unsubscribe ()
246245 return
247246 }
248247 }
@@ -267,6 +266,7 @@ func (api *FilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc.Subsc
267266 if err != nil {
268267 return nil , err
269268 }
269+ defer logsSub .Unsubscribe ()
270270
271271 go func () {
272272 for {
@@ -277,10 +277,8 @@ func (api *FilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc.Subsc
277277 notifier .Notify (rpcSub .ID , & log )
278278 }
279279 case <- rpcSub .Err (): // client send an unsubscribe request
280- logsSub .Unsubscribe ()
281280 return
282281 case <- notifier .Closed (): // connection dropped
283- logsSub .Unsubscribe ()
284282 return
285283 }
286284 }
0 commit comments