Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix interpretation of time.Time{} as a pacing deadline #2980

Merged
merged 1 commit into from
Jan 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/congestion/pacer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (p *pacer) maxBurstSize() protocol.ByteCount {
}

// TimeUntilSend returns when the next packet should be sent.
// It returns the zero value of time.Time if a packet can be sent immediately.
func (p *pacer) TimeUntilSend() time.Time {
if p.budgetAtLastSent >= maxDatagramSize {
return time.Time{}
Expand Down
13 changes: 9 additions & 4 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,10 @@ type session struct {
}

var (
_ Session = &session{}
_ EarlySession = &session{}
_ streamSender = &session{}
_ Session = &session{}
_ EarlySession = &session{}
_ streamSender = &session{}
deadlineSendImmediately = time.Time{}.Add(42 * time.Millisecond) // any value > time.Time{} and before time.Now() is fine
)

var newSession = func(
Expand Down Expand Up @@ -1484,7 +1485,11 @@ func (s *session) sendPackets() error {
}
case ackhandler.SendAny:
if s.handshakeComplete && !s.sentPacketHandler.HasPacingBudget() {
s.pacingDeadline = s.sentPacketHandler.TimeUntilSend()
deadline := s.sentPacketHandler.TimeUntilSend()
if deadline.IsZero() {
deadline = deadlineSendImmediately
}
s.pacingDeadline = deadline
return nil
}
sent, err := s.sendPacket()
Expand Down
20 changes: 19 additions & 1 deletion session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,25 @@ var _ = Describe("Session", func() {
sess.run()
}()
sess.scheduleSending()
time.Sleep(50 * time.Millisecond) // make sure that only 2 packes are sent
time.Sleep(50 * time.Millisecond) // make sure that only 2 packets are sent
})

It("sends multiple packets, when the pacer allows immediate sending", func() {
sph.EXPECT().SentPacket(gomock.Any())
sph.EXPECT().HasPacingBudget()
sph.EXPECT().HasPacingBudget().Return(true).AnyTimes()
sph.EXPECT().TimeUntilSend() // return the zero value of time.Time{}
sph.EXPECT().SendMode().Return(ackhandler.SendAny).Times(3)
packer.EXPECT().PackPacket().Return(getPacket(10), nil)
packer.EXPECT().PackPacket().Return(nil, nil)
mconn.EXPECT().Write(gomock.Any())
go func() {
defer GinkgoRecover()
cryptoSetup.EXPECT().RunHandshake().MaxTimes(1)
sess.run()
}()
sess.scheduleSending()
time.Sleep(50 * time.Millisecond) // make sure that only 1 packet is sent
})

// when becoming congestion limited, at some point the SendMode will change from SendAny to SendAck
Expand Down