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:
Lewis 2025-10-13 20:10:44 +09:00 committed by GitHub
parent 85e9977fae
commit bc0a21a1d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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: