diff --git a/transport/internet/kcp/sending.go b/transport/internet/kcp/sending.go index 2a761ef73..d6e2c1d73 100644 --- a/transport/internet/kcp/sending.go +++ b/transport/internet/kcp/sending.go @@ -61,7 +61,7 @@ func (this *SendingWindow) Remove(idx uint32) { seg.Release() this.data[pos] = nil if pos == this.start { - if this.len == 1 { + if this.start == this.last { this.len = 0 this.start = 0 this.last = 0 diff --git a/transport/internet/kcp/sending_test.go b/transport/internet/kcp/sending_test.go index d6f1539f0..2cb4c8fd0 100644 --- a/transport/internet/kcp/sending_test.go +++ b/transport/internet/kcp/sending_test.go @@ -94,4 +94,15 @@ func TestSendingWindow(t *testing.T) { }) assert.Int(window.Len()).Equals(1) assert.Uint32(window.First().Number).Equals(4) + + window.Push(&DataSegment{ + Number: 5, + }) + assert.Int(window.Len()).Equals(2) + + window.Remove(1) + assert.Int(window.Len()).Equals(2) + + window.Remove(0) + assert.Int(window.Len()).Equals(0) }