Skip to content

Commit bc0a21a

Browse files
authored
eth/filters: uninstall subscription in filter apis on error (#32894)
Fix #32893. In the previous #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.
1 parent 85e9977 commit bc0a21a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

eth/filters/api.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ func (api *FilterAPI) NewPendingTransactionFilter(fullTx *bool) rpc.ID {
143143
api.filtersMu.Unlock()
144144

145145
go func() {
146+
defer pendingTxSub.Unsubscribe()
146147
for {
147148
select {
148149
case pTx := <-pendingTxs:
@@ -155,7 +156,6 @@ func (api *FilterAPI) NewPendingTransactionFilter(fullTx *bool) rpc.ID {
155156
api.filtersMu.Lock()
156157
delete(api.filters, pendingTxSub.ID)
157158
api.filtersMu.Unlock()
158-
pendingTxSub.Unsubscribe()
159159
return
160160
}
161161
}
@@ -218,6 +218,7 @@ func (api *FilterAPI) NewBlockFilter() rpc.ID {
218218
api.filtersMu.Unlock()
219219

220220
go func() {
221+
defer headerSub.Unsubscribe()
221222
for {
222223
select {
223224
case h := <-headers:
@@ -403,6 +404,7 @@ func (api *FilterAPI) NewFilter(crit FilterCriteria) (rpc.ID, error) {
403404
api.filtersMu.Unlock()
404405

405406
go func() {
407+
defer logsSub.Unsubscribe()
406408
for {
407409
select {
408410
case l := <-logs:

0 commit comments

Comments
 (0)