Merge pull request #399 from j75689/fix/issue_388

fix: nil pointer issue (#388)
This commit is contained in:
dylanhuang 2021-09-01 22:04:04 +08:00 committed by GitHub
commit 2d2740e2a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 14 deletions

@ -117,16 +117,19 @@ func (api *PublicFilterAPI) NewPendingTransactionFilter() rpc.ID {
pendingTxs = make(chan []common.Hash)
pendingTxSub = api.events.SubscribePendingTxs(pendingTxs)
)
f := &filter{typ: PendingTransactionsSubscription, deadline: time.NewTimer(api.timeout), hashes: make([]common.Hash, 0), s: pendingTxSub}
api.filtersMu.Lock()
api.filters[pendingTxSub.ID] = f
api.filters[pendingTxSub.ID] = &filter{typ: PendingTransactionsSubscription, deadline: time.NewTimer(api.timeout), hashes: make([]common.Hash, 0), s: pendingTxSub}
api.filtersMu.Unlock()
gopool.Submit(func() {
for {
select {
case ph := <-pendingTxs:
f.hashes = append(f.hashes, ph...)
api.filtersMu.Lock()
if f, found := api.filters[pendingTxSub.ID]; found {
f.hashes = append(f.hashes, ph...)
}
api.filtersMu.Unlock()
case <-pendingTxSub.Err():
api.filtersMu.Lock()
delete(api.filters, pendingTxSub.ID)

@ -174,17 +174,6 @@ func (sub *Subscription) Unsubscribe() {
// this ensures that the manager won't use the event channel which
// will probably be closed by the client asap after this method returns.
<-sub.Err()
drainLoop:
for {
select {
case <-sub.f.logs:
case <-sub.f.hashes:
case <-sub.f.headers:
default:
break drainLoop
}
}
})
}