mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 19:00:46 +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()
|
api.filtersMu.Unlock()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
defer pendingTxSub.Unsubscribe()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case pTx := <-pendingTxs:
|
case pTx := <-pendingTxs:
|
||||||
|
|
@ -155,7 +156,6 @@ func (api *FilterAPI) NewPendingTransactionFilter(fullTx *bool) rpc.ID {
|
||||||
api.filtersMu.Lock()
|
api.filtersMu.Lock()
|
||||||
delete(api.filters, pendingTxSub.ID)
|
delete(api.filters, pendingTxSub.ID)
|
||||||
api.filtersMu.Unlock()
|
api.filtersMu.Unlock()
|
||||||
pendingTxSub.Unsubscribe()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -218,6 +218,7 @@ func (api *FilterAPI) NewBlockFilter() rpc.ID {
|
||||||
api.filtersMu.Unlock()
|
api.filtersMu.Unlock()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
defer headerSub.Unsubscribe()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case h := <-headers:
|
case h := <-headers:
|
||||||
|
|
@ -403,6 +404,7 @@ func (api *FilterAPI) NewFilter(crit FilterCriteria) (rpc.ID, error) {
|
||||||
api.filtersMu.Unlock()
|
api.filtersMu.Unlock()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
defer logsSub.Unsubscribe()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case l := <-logs:
|
case l := <-logs:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue