Skip to content

Commit

Permalink
tracker: fix byte counter leak in Inflights tracker
Browse files Browse the repository at this point in the history
This change fixes a bug in the Inflights tracker. The reset() method did not
zero the bytes counter, which could result in a quota "leak" and delayed or
stalled MsgApp sends.

The reset() method is used when the replication flow changes state between
Probe/Replicate/Snapshot. If reset() is not called at an appropriate moment,
when Inflights.Full(), the bytes counter would stay over the budget and stall
the flow.

Signed-off-by: Pavel Kalinnikov <[email protected]>
  • Loading branch information
pav-kv committed May 18, 2023
1 parent 177ef28 commit e419ba5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tracker/inflights.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func (in *Inflights) Count() int { return in.count }

// reset frees all inflights.
func (in *Inflights) reset() {
in.count = 0
in.start = 0
in.count = 0
in.bytes = 0
}
22 changes: 22 additions & 0 deletions tracker/inflights_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,28 @@ func TestInflightsFull(t *testing.T) {
}
}

func TestInflightsReset(t *testing.T) {
in := NewInflights(10, 1000)
// Imitate a semi-realistic flow during which the inflight tracker is
// periodically reset to empty. Byte usage must not "leak" across resets.
index := uint64(0)
for epoch := 0; epoch < 100; epoch++ {
in.reset()
// Add 5 messages. They should not max out the limit yet.
for i := 0; i < 5; i++ {
require.False(t, in.Full())
index++
in.Add(index, 16)
}
// Ack all but last 2 indices.
in.FreeLE(index - 2)
require.False(t, in.Full())
require.Equal(t, 2, in.Count())
}
in.FreeLE(index)
require.Equal(t, 0, in.Count())
}

func inflightsBuffer(indices []uint64, sizes []uint64) []inflight {
if len(indices) != len(sizes) {
panic("len(indices) != len(sizes)")
Expand Down

0 comments on commit e419ba5

Please sign in to comment.