mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-04-01 07:35:58 +00:00
eth/filters: uninstall subscription in filter apis on error (#32894)
Fix https://github.com/ethereum/go-ethereum/issues/32893. In the previous https://github.com/ethereum/go-ethereum/pull/32794, it only handles the pending tx filter, while there are also head and log filters. This PR applies the patch to all filter APIs and uses `defer` to maintain code consistency.
This commit is contained in:
parent
85e9977fae
commit
bc0a21a1d5
1 changed files with 3 additions and 1 deletions
|
|
@ -143,6 +143,7 @@ func (api *FilterAPI) NewPendingTransactionFilter(fullTx *bool) rpc.ID {
|
|||
api.filtersMu.Unlock()
|
||||
|
||||
go func() {
|
||||
defer pendingTxSub.Unsubscribe()
|
||||
for {
|
||||
select {
|
||||
case pTx := <-pendingTxs:
|
||||
|
|
@ -155,7 +156,6 @@ func (api *FilterAPI) NewPendingTransactionFilter(fullTx *bool) rpc.ID {
|
|||
api.filtersMu.Lock()
|
||||
delete(api.filters, pendingTxSub.ID)
|
||||
api.filtersMu.Unlock()
|
||||
pendingTxSub.Unsubscribe()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -218,6 +218,7 @@ func (api *FilterAPI) NewBlockFilter() rpc.ID {
|
|||
api.filtersMu.Unlock()
|
||||
|
||||
go func() {
|
||||
defer headerSub.Unsubscribe()
|
||||
for {
|
||||
select {
|
||||
case h := <-headers:
|
||||
|
|
@ -403,6 +404,7 @@ func (api *FilterAPI) NewFilter(crit FilterCriteria) (rpc.ID, error) {
|
|||
api.filtersMu.Unlock()
|
||||
|
||||
go func() {
|
||||
defer logsSub.Unsubscribe()
|
||||
for {
|
||||
select {
|
||||
case l := <-logs:
|
||||
|
|
|
|||
Loading…
Reference in a new issue