From 2dad0f040586fa32a081e47cc01aba55a9772251 Mon Sep 17 00:00:00 2001 From: Sylvain Rabot Date: Fri, 23 Dec 2022 11:56:48 +0400 Subject: [PATCH] Align session's ticker with round second Co-authored-by: Alexis Masson Signed-off-by: Sylvain Rabot --- session.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/session.go b/session.go index 331af0f0f..e2ee4344f 100644 --- a/session.go +++ b/session.go @@ -754,6 +754,14 @@ func (s *session) run() { } }) + + // Without this sleep the ticker will be aligned at the millisecond which + // corresponds to the creation of the session. If the session creation + // happened at 07:00:00.678 and the session StartTime is 07:30:00, any new + // connection received between 07:30:00.000 and 07:30:00.677 will be + // rejected. Aligning the ticker with a round second fixes that. + time.Sleep(time.Until(time.Now().Truncate(time.Second).Add(time.Second))) + ticker := time.NewTicker(time.Second) defer func() {