Skip to content

Commit

Permalink
fix: BBR memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyxdd committed Oct 11, 2023
1 parent 5597b48 commit 7c46e84
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions core/internal/congestion/bbr/bbr_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,19 @@ func (b *bbrSender) OnCongestionEventEx(priorInFlight congestion.ByteCount, even
b.calculateRecoveryWindow(bytesAcked, bytesLost)

// Cleanup internal state.
if len(lostPackets) != 0 {
lastLostPacket := lostPackets[len(lostPackets)-1].PacketNumber
b.sampler.RemoveObsoletePackets(lastLostPacket)
// This is where we clean up obsolete (acked or lost) packets from the bandwidth sampler.
// The "least unacked" should actually be FirstOutstanding, but since we are not passing
// that through OnCongestionEventEx, we will only do an estimate using acked/lost packets
// for now. Because of fast retransmission, they should differ by no more than 2 packets.
// (this is controlled by packetThreshold in quic-go's sentPacketHandler)
var leastUnacked congestion.PacketNumber
if len(ackedPackets) != 0 {
leastUnacked = ackedPackets[len(ackedPackets)-1].PacketNumber - 2
} else {
leastUnacked = lostPackets[len(lostPackets)-1].PacketNumber + 1
}
b.sampler.RemoveObsoletePackets(leastUnacked)

if isRoundStart {
b.numLossEventsInRound = 0
b.bytesLostInRound = 0
Expand Down

0 comments on commit 7c46e84

Please sign in to comment.