Skip to content

Commit

Permalink
fix: bind after session close
Browse files Browse the repository at this point in the history
  • Loading branch information
liurunzhi committed May 26, 2023
1 parent 177d08b commit 9aaf7cf
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ func (s *sessionImpl) Bind(ctx context.Context, uid string) error {
return constants.ErrSessionAlreadyBound
}

if _, ok := s.pool.sessionsByID.Load(s.ID()); !ok {
return constants.ErrConnectionClosed
}

s.uid = uid
for _, cb := range s.pool.sessionBindCallbacks {
err := cb(ctx, s)
Expand Down Expand Up @@ -412,6 +416,19 @@ func (s *sessionImpl) Bind(ctx context.Context, uid string) error {
return err
}
}

// double check
if _, ok := s.pool.sessionsByID.Load(s.ID()); !ok {
for _, sub := range s.GetSubscriptions() {
err := sub.Unsubscribe()
log := logger.Log
if err != nil {
log = log.WithError(err)
}
log.Debug("unsubscribe to user's %s message channel, because it close the network", s.UID())
}
return constants.ErrConnectionClosed
}
return nil
}

Expand All @@ -434,6 +451,11 @@ func (s *sessionImpl) OnClose(c func()) error {
if !s.IsFrontend {
return constants.ErrOnCloseBackend
}

if _, ok := s.pool.sessionsByID.Load(s.ID()); !ok {
return constants.ErrConnectionClosed
}

s.OnCloseCallbacks = append(s.OnCloseCallbacks, c)
return nil
}
Expand Down

0 comments on commit 9aaf7cf

Please sign in to comment.