From 66598652962cae72b89271ecc5310f0bd4442639 Mon Sep 17 00:00:00 2001 From: SNORRIS721 Date: Fri, 3 May 2024 10:36:01 -0500 Subject: [PATCH 1/2] Unregistering sessions on initiator close --- initiator.go | 8 ++++++++ session_factory_test.go | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/initiator.go b/initiator.go index 1b48ce4ce..b8735e388 100644 --- a/initiator.go +++ b/initiator.go @@ -73,6 +73,14 @@ func (i *Initiator) Stop() { default: } close(i.stopChan) + + for sessionID := range i.sessionSettings { + err := UnregisterSession(sessionID) + if err != nil { + return + } + } + i.wg.Wait() } diff --git a/session_factory_test.go b/session_factory_test.go index d14c5b221..349e7580c 100644 --- a/session_factory_test.go +++ b/session_factory_test.go @@ -472,6 +472,23 @@ func (s *SessionFactorySuite) TestNewSessionBuildInitiators() { s.Equal("127.0.0.1:5000", session.SocketConnectAddress[0]) } +func (s *SessionFactorySuite) TestDuplicateSession() { + s.sessionFactory.BuildInitiators = true + s.SessionSettings.Set(config.HeartBtInt, "34") + s.SessionSettings.Set(config.SocketConnectHost, "127.0.0.1") + s.SessionSettings.Set(config.SocketConnectPort, "5000") + + session, err := s.createSession(s.SessionID, s.MessageStoreFactory, s.SessionSettings, s.LogFactory, s.App) + s.Nil(err) + s.True(session.InitiateLogon) + _, err = s.createSession(s.SessionID, s.MessageStoreFactory, s.SessionSettings, s.LogFactory, s.App) + s.NotNil(err) + s.Equal("Duplicate SessionID", err.Error()) + UnregisterSession(s.SessionID) + _, err = s.createSession(s.SessionID, s.MessageStoreFactory, s.SessionSettings, s.LogFactory, s.App) + s.Nil(err) +} + func (s *SessionFactorySuite) TestNewSessionBuildAcceptors() { s.sessionFactory.BuildInitiators = false s.SessionSettings.Set(config.HeartBtInt, "34") From cf3fb987067e504e3c9105e95161008d496f5f55 Mon Sep 17 00:00:00 2001 From: SNORRIS721 Date: Fri, 3 May 2024 13:50:51 -0500 Subject: [PATCH 2/2] Unregistering sessions on acceptor stop --- acceptor.go | 7 +++++++ initiator.go | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/acceptor.go b/acceptor.go index 968be9efb..da4cd9bb0 100644 --- a/acceptor.go +++ b/acceptor.go @@ -144,6 +144,13 @@ func (a *Acceptor) Stop() { session.stop() } a.sessionGroup.Wait() + + for sessionID := range a.sessions { + err := UnregisterSession(sessionID) + if err != nil { + return + } + } } // RemoteAddr gets remote IP address for a given session. diff --git a/initiator.go b/initiator.go index b8735e388..eeff30fc0 100644 --- a/initiator.go +++ b/initiator.go @@ -74,14 +74,14 @@ func (i *Initiator) Stop() { } close(i.stopChan) + i.wg.Wait() + for sessionID := range i.sessionSettings { err := UnregisterSession(sessionID) if err != nil { return } } - - i.wg.Wait() } // NewInitiator creates and initializes a new Initiator.