don't set the idle timeout timer before the handshake completes

This commit is contained in:
Marten Seemann
2019-12-11 13:50:13 +04:00
parent e9bced8d73
commit 8dcca046e3
2 changed files with 14 additions and 12 deletions

View File

@@ -569,11 +569,16 @@ func (s *session) ConnectionState() tls.ConnectionState {
func (s *session) maybeResetTimer() { func (s *session) maybeResetTimer() {
var deadline time.Time var deadline time.Time
if s.config.KeepAlive && s.handshakeComplete && !s.keepAlivePingSent { if !s.handshakeComplete {
handshakeDeadline := s.sessionCreationTime.Add(s.config.HandshakeTimeout)
deadline = handshakeDeadline
} else {
if s.config.KeepAlive && !s.keepAlivePingSent {
deadline = s.idleTimeoutStartTime().Add(s.keepAliveInterval / 2) deadline = s.idleTimeoutStartTime().Add(s.keepAliveInterval / 2)
} else { } else {
deadline = s.idleTimeoutStartTime().Add(s.config.IdleTimeout) deadline = s.idleTimeoutStartTime().Add(s.config.IdleTimeout)
} }
}
if ackAlarm := s.receivedPacketHandler.GetAlarmTimeout(); !ackAlarm.IsZero() { if ackAlarm := s.receivedPacketHandler.GetAlarmTimeout(); !ackAlarm.IsZero() {
deadline = utils.MinTime(deadline, ackAlarm) deadline = utils.MinTime(deadline, ackAlarm)
@@ -581,10 +586,6 @@ func (s *session) maybeResetTimer() {
if lossTime := s.sentPacketHandler.GetLossDetectionTimeout(); !lossTime.IsZero() { if lossTime := s.sentPacketHandler.GetLossDetectionTimeout(); !lossTime.IsZero() {
deadline = utils.MinTime(deadline, lossTime) deadline = utils.MinTime(deadline, lossTime)
} }
if !s.handshakeComplete {
handshakeDeadline := s.sessionCreationTime.Add(s.config.HandshakeTimeout)
deadline = utils.MinTime(deadline, handshakeDeadline)
}
if !s.pacingDeadline.IsZero() { if !s.pacingDeadline.IsZero() {
deadline = utils.MinTime(deadline, s.pacingDeadline) deadline = utils.MinTime(deadline, s.pacingDeadline)
} }

View File

@@ -131,6 +131,7 @@ var _ = Describe("Session", func() {
sess.packer = packer sess.packer = packer
cryptoSetup = mocks.NewMockCryptoSetup(mockCtrl) cryptoSetup = mocks.NewMockCryptoSetup(mockCtrl)
sess.cryptoStreamHandler = cryptoSetup sess.cryptoStreamHandler = cryptoSetup
sess.handshakeComplete = true
}) })
AfterEach(func() { AfterEach(func() {
@@ -466,7 +467,6 @@ var _ = Describe("Session", func() {
}) })
It("closes with an error", func() { It("closes with an error", func() {
sess.handshakeComplete = true
streamManager.EXPECT().CloseWithError(qerr.ApplicationError(0x1337, "test error")) streamManager.EXPECT().CloseWithError(qerr.ApplicationError(0x1337, "test error"))
expectReplaceWithClosed() expectReplaceWithClosed()
cryptoSetup.EXPECT().Close() cryptoSetup.EXPECT().Close()
@@ -482,7 +482,6 @@ var _ = Describe("Session", func() {
}) })
It("includes the frame type in transport-level close frames", func() { It("includes the frame type in transport-level close frames", func() {
sess.handshakeComplete = true
testErr := qerr.ErrorWithFrameType(0x1337, 0x42, "test error") testErr := qerr.ErrorWithFrameType(0x1337, 0x42, "test error")
streamManager.EXPECT().CloseWithError(testErr) streamManager.EXPECT().CloseWithError(testErr)
expectReplaceWithClosed() expectReplaceWithClosed()
@@ -500,6 +499,7 @@ var _ = Describe("Session", func() {
}) })
It("doesn't send application-level error before the handshake completes", func() { It("doesn't send application-level error before the handshake completes", func() {
sess.handshakeComplete = false
streamManager.EXPECT().CloseWithError(qerr.ApplicationError(0x1337, "test error")) streamManager.EXPECT().CloseWithError(qerr.ApplicationError(0x1337, "test error"))
expectReplaceWithClosed() expectReplaceWithClosed()
cryptoSetup.EXPECT().Close() cryptoSetup.EXPECT().Close()
@@ -764,6 +764,7 @@ var _ = Describe("Session", func() {
}) })
It("queues undecryptable packets", func() { It("queues undecryptable packets", func() {
sess.handshakeComplete = false
hdr := &wire.ExtendedHeader{ hdr := &wire.ExtendedHeader{
Header: wire.Header{ Header: wire.Header{
IsLongHeader: true, IsLongHeader: true,
@@ -856,6 +857,7 @@ var _ = Describe("Session", func() {
}) })
It("works with undecryptable packets", func() { It("works with undecryptable packets", func() {
sess.handshakeComplete = false
hdrLen1, packet1 := getPacketWithLength(srcConnID, 456) hdrLen1, packet1 := getPacketWithLength(srcConnID, 456)
hdrLen2, packet2 := getPacketWithLength(srcConnID, 123) hdrLen2, packet2 := getPacketWithLength(srcConnID, 123)
gomock.InOrder( gomock.InOrder(
@@ -1371,7 +1373,6 @@ var _ = Describe("Session", func() {
BeforeEach(func() { BeforeEach(func() {
sess.config.KeepAlive = true sess.config.KeepAlive = true
sess.handshakeComplete = true
}) })
AfterEach(func() { AfterEach(func() {
@@ -1433,7 +1434,6 @@ var _ = Describe("Session", func() {
It("times out due to no network activity", func() { It("times out due to no network activity", func() {
sessionRunner.EXPECT().Remove(gomock.Any()).Times(2) sessionRunner.EXPECT().Remove(gomock.Any()).Times(2)
sess.handshakeComplete = true
sess.lastPacketReceivedTime = time.Now().Add(-time.Hour) sess.lastPacketReceivedTime = time.Now().Add(-time.Hour)
done := make(chan struct{}) done := make(chan struct{})
cryptoSetup.EXPECT().Close() cryptoSetup.EXPECT().Close()
@@ -1451,6 +1451,7 @@ var _ = Describe("Session", func() {
}) })
It("times out due to non-completed handshake", func() { It("times out due to non-completed handshake", func() {
sess.handshakeComplete = false
sess.sessionCreationTime = time.Now().Add(-protocol.DefaultHandshakeTimeout).Add(-time.Second) sess.sessionCreationTime = time.Now().Add(-protocol.DefaultHandshakeTimeout).Add(-time.Second)
sessionRunner.EXPECT().Remove(gomock.Any()).Times(2) sessionRunner.EXPECT().Remove(gomock.Any()).Times(2)
cryptoSetup.EXPECT().Close() cryptoSetup.EXPECT().Close()
@@ -1469,6 +1470,7 @@ var _ = Describe("Session", func() {
}) })
It("does not use the idle timeout before the handshake complete", func() { It("does not use the idle timeout before the handshake complete", func() {
sess.handshakeComplete = false
sess.config.IdleTimeout = 9999 * time.Second sess.config.IdleTimeout = 9999 * time.Second
sess.lastPacketReceivedTime = time.Now().Add(-time.Minute) sess.lastPacketReceivedTime = time.Now().Add(-time.Minute)
packer.EXPECT().PackConnectionClose(gomock.Any()).DoAndReturn(func(f *wire.ConnectionCloseFrame) (*packedPacket, error) { packer.EXPECT().PackConnectionClose(gomock.Any()).DoAndReturn(func(f *wire.ConnectionCloseFrame) (*packedPacket, error) {
@@ -1515,7 +1517,6 @@ var _ = Describe("Session", func() {
}) })
It("doesn't time out when it just sent a packet", func() { It("doesn't time out when it just sent a packet", func() {
sess.handshakeComplete = true
sess.lastPacketReceivedTime = time.Now().Add(-time.Hour) sess.lastPacketReceivedTime = time.Now().Add(-time.Hour)
sess.firstAckElicitingPacketAfterIdleSentTime = time.Now().Add(-time.Second) sess.firstAckElicitingPacketAfterIdleSentTime = time.Now().Add(-time.Second)
sess.config.IdleTimeout = 30 * time.Second sess.config.IdleTimeout = 30 * time.Second