Merge pull request #2516 from lucas-clemente/stop-timer

stop the timer when the session's run loop returns
This commit is contained in:
Marten Seemann
2020-05-02 09:46:36 +07:00
committed by GitHub
3 changed files with 15 additions and 1 deletions

View File

@@ -46,3 +46,8 @@ func (t *Timer) Reset(deadline time.Time) {
func (t *Timer) SetRead() {
t.read = true
}
// Stop stops the timer
func (t *Timer) Stop() {
t.t.Stop()
}

View File

@@ -77,4 +77,11 @@ var _ = Describe("Timer", func() {
Eventually(t.Chan()).Should(Receive())
Consistently(t.Chan()).ShouldNot(Receive())
})
It("stops", func() {
t := NewTimer()
t.Reset(time.Now().Add(50 * time.Millisecond))
t.Stop()
Consistently(t.Chan()).ShouldNot(Receive())
})
})

View File

@@ -472,7 +472,6 @@ func (s *session) preSetup() {
s.ctx, s.ctxCancel = context.WithCancel(context.Background())
s.handshakeCtx, s.handshakeCtxCancel = context.WithCancel(context.Background())
s.timer = utils.NewTimer()
now := time.Now()
s.lastPacketReceivedTime = now
s.sessionCreationTime = now
@@ -490,6 +489,8 @@ func (s *session) preSetup() {
func (s *session) run() error {
defer s.ctxCancel()
s.timer = utils.NewTimer()
go s.cryptoStreamHandler.RunHandshake()
go func() {
if err := s.sendQueue.Run(); err != nil {
@@ -605,6 +606,7 @@ runLoop:
s.logger.Infof("Connection %s closed.", s.logID)
s.cryptoStreamHandler.Close()
s.sendQueue.Close()
s.timer.Stop()
return closeErr.err
}