mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 08:49:29 +00:00
eth/txtracker: compact FIFO order slice to prevent memory leak
order = order[1:] reslices without releasing the backing array. After N total insertions the array retains N hashes (32 bytes each) but only the last maxTracked are live. On a long-running node processing ~100 txs/s this leaks ~275 MB/day. Compact by copying to a fresh array when capacity exceeds 2×maxTracked.
This commit is contained in:
parent
803ac3c641
commit
7f1720b3dc
1 changed files with 5 additions and 0 deletions
|
|
@ -137,6 +137,11 @@ func (t *Tracker) NotifyAccepted(peer string, hashes []common.Hash) {
|
|||
t.order = t.order[1:]
|
||||
delete(t.txs, oldest)
|
||||
}
|
||||
// Compact the backing array when it grows too large. Reslicing
|
||||
// with order[1:] doesn't free earlier slots in the array.
|
||||
if cap(t.order) > 2*maxTracked {
|
||||
t.order = append([]common.Hash(nil), t.order...)
|
||||
}
|
||||
}
|
||||
|
||||
// GetAllPeerStats returns a snapshot of per-peer inclusion statistics.
|
||||
|
|
|
|||
Loading…
Reference in a new issue