Skip to content

Commit

Permalink
Merge pull request #637 from SNORRIS721/duplicatesession
Browse files Browse the repository at this point in the history
Unregistering sessions on stop
  • Loading branch information
ackleymi committed May 7, 2024
2 parents c187bdb + cf3fb98 commit 1205f67
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions acceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions initiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ func (i *Initiator) Stop() {
default:
}
close(i.stopChan)

i.wg.Wait()

for sessionID := range i.sessionSettings {
err := UnregisterSession(sessionID)
if err != nil {
return
}
}
}

// NewInitiator creates and initializes a new Initiator.
Expand Down
17 changes: 17 additions & 0 deletions session_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 1205f67

Please sign in to comment.