fix: memory leak accumulation in pending frame processing (#59)

This commit is contained in:
Cassandra Heart 2024-02-20 17:12:29 -06:00 committed by GitHub
parent 5405452f3e
commit 9fc46fff2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 2 deletions

View File

@ -30,7 +30,7 @@ import (
)
const PEER_INFO_TTL = 60 * 60 * 1000
const UNCOOPERATIVE_PEER_INFO_TTL = 60 * 60 * 1000
const UNCOOPERATIVE_PEER_INFO_TTL = 5 * 60 * 1000
type InclusionMap = map[curves.PairingPoint]*protobufs.InclusionCommitment
type PolynomialMap = map[curves.PairingPoint][]curves.PairingScalar

View File

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/hex"
"math/big"
"sort"
"sync"
lru "github.com/hashicorp/golang-lru/v2"
@ -462,7 +463,23 @@ func (d *DataTimeReel) processPending(
frame *protobufs.ClockFrame,
) {
d.logger.Debug("process pending")
for f, nextPending := range d.pending {
frameNumbers := []uint64{}
for f := range d.pending {
frameNumbers = append(frameNumbers, f)
}
sort.Slice(frameNumbers, func(i, j int) bool {
return frameNumbers[i] < frameNumbers[j]
})
limit := 8
for _, f := range frameNumbers {
if f < d.head.FrameNumber {
delete(d.pending, f)
}
if limit <= 0 {
return
}
nextPending := d.pending[f]
d.logger.Debug(
"checking frame set",
zap.Uint64("pending_frame_number", f),
@ -498,7 +515,9 @@ func (d *DataTimeReel) processPending(
go func() {
d.frames <- nextFrame
}()
limit--
}
if len(d.pending[f]) == 0 {
d.logger.Debug("last next processing, clear list")
delete(d.pending, f)