Skip to content

Commit 11e8be0

Browse files
mmsqevladjdk
andauthored
fix: cleanup unused cancel function in filter (#452)
* fix: cleanup unused cancel function in filter * doc * test --------- Co-authored-by: Vlad J <vladjdk@gmail.com>
1 parent eb60af8 commit 11e8be0

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- [\#376](https://github.com/cosmos/evm/pull/376) Fix precompile initialization for local node development script
2323
- [\#384](https://github.com/cosmos/evm/pull/384) Fix debug_traceTransaction RPC failing with block height mismatch errors
2424
- [\#441](https://github.com/cosmos/evm/pull/441) Align precompiles map with available static check to Prague.
25+
- [\#452](https://github.com/cosmos/evm/pull/452) Cleanup unused cancel function in filter.
2526
- [\#454](https://github.com/cosmos/evm/pull/454) Align multi decode functions instead of string contains check in HexAddressFromBech32String.
2627

2728
### IMPROVEMENTS

rpc/namespaces/ethereum/eth/filters/api.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ type filter struct {
6565
typ filters.Type
6666
deadline *time.Timer // filter is inactive when deadline triggers
6767
crit filters.FilterCriteria
68-
cancel context.CancelFunc
6968
offset int // offset for stream subscription
7069
}
7170

@@ -128,7 +127,6 @@ func (api *PublicFilterAPI) timeoutLoop() {
128127
for id, f := range api.filters {
129128
select {
130129
case <-f.deadline.C:
131-
f.cancel()
132130
delete(api.filters, id)
133131
default:
134132
continue
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package filters
2+
3+
import (
4+
"sync"
5+
"testing"
6+
"time"
7+
8+
"github.com/ethereum/go-ethereum/eth/filters"
9+
"github.com/ethereum/go-ethereum/rpc"
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
func TestTimeoutLoop_PanicOnNilCancel(t *testing.T) {
14+
api := &PublicFilterAPI{
15+
filters: make(map[rpc.ID]*filter),
16+
filtersMu: sync.Mutex{},
17+
deadline: 10 * time.Millisecond,
18+
}
19+
api.filters[rpc.NewID()] = &filter{
20+
typ: filters.BlocksSubscription,
21+
deadline: time.NewTimer(0),
22+
}
23+
done := make(chan struct{})
24+
go func() {
25+
defer func() {
26+
if r := recover(); r == nil {
27+
t.Errorf("cancel panic")
28+
}
29+
close(done)
30+
}()
31+
api.timeoutLoop()
32+
}()
33+
panicked := false
34+
select {
35+
case <-done:
36+
panicked = true
37+
case <-time.After(100 * time.Millisecond):
38+
}
39+
require.False(t, panicked)
40+
}

0 commit comments

Comments
 (0)