tests/fuzzers: fix goroutine leak in les fuzzer (#22455)
The oss-fuzz fuzzer has been reporting some failing testcases for les. They're all spurious, and cannot reliably be reproduced. However, running them showed that there was a goroutine leak: the tests created a lot of new clients, which started an exec queue that was never torn down. This PR fixes the goroutine leak, and also a log message which was erroneously formatted.
This commit is contained in:
parent
faacc8e0fa
commit
bc47993692
@ -206,8 +206,8 @@ func handleGetBlockHeaders(msg Decoder) (serveRequestFn, uint64, uint64, error)
|
|||||||
next = current + r.Query.Skip + 1
|
next = current + r.Query.Skip + 1
|
||||||
)
|
)
|
||||||
if next <= current {
|
if next <= current {
|
||||||
infos, _ := json.MarshalIndent(p.Peer.Info(), "", " ")
|
infos, _ := json.Marshal(p.Peer.Info())
|
||||||
p.Log().Warn("GetBlockHeaders skip overflow attack", "current", current, "skip", r.Query.Skip, "next", next, "attacker", infos)
|
p.Log().Warn("GetBlockHeaders skip overflow attack", "current", current, "skip", r.Query.Skip, "next", next, "attacker", string(infos))
|
||||||
unknown = true
|
unknown = true
|
||||||
} else {
|
} else {
|
||||||
if header := bc.GetHeaderByNumber(next); header != nil {
|
if header := bc.GetHeaderByNumber(next); header != nil {
|
||||||
|
@ -661,6 +661,10 @@ func newClientServerEnv(t *testing.T, config testnetConfig) (*testServer, *testC
|
|||||||
return s, c, teardown
|
return s, c, teardown
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFuzzerPeer(version int) *clientPeer {
|
// NewFuzzerPeer creates a client peer for test purposes, and also returns
|
||||||
return newClientPeer(version, 0, p2p.NewPeer(enode.ID{}, "", nil), nil)
|
// a function to close the peer: this is needed to avoid goroutine leaks in the
|
||||||
|
// exec queue.
|
||||||
|
func NewFuzzerPeer(version int) (p *clientPeer, closer func()) {
|
||||||
|
p = newClientPeer(version, 0, p2p.NewPeer(enode.ID{}, "", nil), nil)
|
||||||
|
return p, func() { p.peerCommons.close() }
|
||||||
}
|
}
|
||||||
|
@ -261,18 +261,18 @@ func (d dummyMsg) Decode(val interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *fuzzer) doFuzz(msgCode uint64, packet interface{}) {
|
func (f *fuzzer) doFuzz(msgCode uint64, packet interface{}) {
|
||||||
version := f.randomInt(3) + 2 // [LES2, LES3, LES4]
|
|
||||||
peer := l.NewFuzzerPeer(version)
|
|
||||||
enc, err := rlp.EncodeToBytes(packet)
|
enc, err := rlp.EncodeToBytes(packet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
version := f.randomInt(3) + 2 // [LES2, LES3, LES4]
|
||||||
|
peer, closeFn := l.NewFuzzerPeer(version)
|
||||||
|
defer closeFn()
|
||||||
fn, _, _, err := l.Les3[msgCode].Handle(dummyMsg{enc})
|
fn, _, _, err := l.Les3[msgCode].Handle(dummyMsg{enc})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
fn(f, peer, func() bool { return true })
|
fn(f, peer, func() bool { return true })
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Fuzz(input []byte) int {
|
func Fuzz(input []byte) int {
|
||||||
|
Loading…
Reference in New Issue
Block a user