From c855c338bde47832b273f6f6b39458f04c1d2d25 Mon Sep 17 00:00:00 2001 From: momin-javed Date: Fri, 14 Jun 2024 15:31:04 +0530 Subject: [PATCH 1/2] Do not increment targetMsgSeqNum for out of sequence logout and test requests --- in_session.go | 25 +++++++++++++++++++++---- in_session_test.go | 17 +++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/in_session.go b/in_session.go index 6f189bf49..62304d005 100644 --- a/in_session.go +++ b/in_session.go @@ -102,14 +102,23 @@ func (state inSession) handleLogout(session *session, msg *Message) (nextState s session.log.OnEvent("Received logout response") } - if err := session.store.IncrNextTargetMsgSeqNum(); err != nil { - session.logError(err) - } - if session.ResetOnLogout { if err := session.dropAndReset(); err != nil { session.logError(err) } + return latentState{} + } + + if err := session.checkTargetTooLow(msg); err != nil { + return latentState{} + } + + if err := session.checkTargetTooHigh(msg); err != nil { + return latentState{} + } + + if err := session.store.IncrNextTargetMsgSeqNum(); err != nil { + session.logError(err) } return latentState{} @@ -131,6 +140,14 @@ func (state inSession) handleTestRequest(session *session, msg *Message) (nextSt } } + if err := session.checkTargetTooLow(msg); err != nil { + return state + } + + if err := session.checkTargetTooHigh(msg); err != nil { + return state + } + if err := session.store.IncrNextTargetMsgSeqNum(); err != nil { return handleStateError(session, err) } diff --git a/in_session_test.go b/in_session_test.go index aa9f87084..8973e4ef0 100644 --- a/in_session_test.go +++ b/in_session_test.go @@ -96,6 +96,23 @@ func (s *InSessionTestSuite) TestLogoutResetOnLogout() { s.NoMessageQueued() } +func (s *InSessionTestSuite) TestLogoutTargetTooHigh() { + s.MessageFactory.seqNum = 5 + + s.MockApp.On("FromAdmin").Return(nil) + s.MockApp.On("ToAdmin") + s.MockApp.On("OnLogout") + s.session.fixMsgIn(s.session, s.Logout()) + + s.MockApp.AssertExpectations(s.T()) + s.State(latentState{}) + + s.LastToAdminMessageSent() + s.MessageType(string(msgTypeLogout), s.MockApp.lastToAdmin) + s.NextTargetMsgSeqNum(1) + s.NextSenderMsgSeqNum(2) +} + func (s *InSessionTestSuite) TestTimeoutNeedHeartbeat() { s.MockApp.On("ToAdmin").Return(nil) s.session.Timeout(s.session, internal.NeedHeartbeat) From a60af80ed30435dd26a636423ffa1cc6432ad3ca Mon Sep 17 00:00:00 2001 From: momin-javed Date: Wed, 26 Jun 2024 00:45:06 +0530 Subject: [PATCH 2/2] Revert redundant TestRequest change --- in_session.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/in_session.go b/in_session.go index 62304d005..816b4b240 100644 --- a/in_session.go +++ b/in_session.go @@ -140,14 +140,6 @@ func (state inSession) handleTestRequest(session *session, msg *Message) (nextSt } } - if err := session.checkTargetTooLow(msg); err != nil { - return state - } - - if err := session.checkTargetTooHigh(msg); err != nil { - return state - } - if err := session.store.IncrNextTargetMsgSeqNum(); err != nil { return handleStateError(session, err) }