Fix check for async room messages received while not joined to a room.

This commit is contained in:
Joachim Bauch 2022-06-14 16:38:29 +02:00
parent 26f9edd476
commit 078768f9c8
No known key found for this signature in database
GPG Key ID: 77C1D22D53E15F02
1 changed files with 7 additions and 2 deletions

View File

@ -340,7 +340,12 @@ func (s *ClientSession) GetRoom() *Room {
}
func (s *ClientSession) getRoomJoinTime() time.Time {
return time.Unix(0, atomic.LoadInt64(&s.roomJoinTime))
t := atomic.LoadInt64(&s.roomJoinTime)
if t == 0 {
return time.Time{}
}
return time.Unix(0, t)
}
func (s *ClientSession) releaseMcuObjects() {
@ -1169,7 +1174,7 @@ func (s *ClientSession) processNatsMessage(msg *NatsMessage) *ServerMessage {
if msg.Message.Event.Target == "room" {
// Can happen mostly during tests where an older room NATS message
// could be received by a subscriber that joined after it was sent.
if msg.SendTime.Before(s.getRoomJoinTime()) {
if joined := s.getRoomJoinTime(); joined.IsZero() || msg.SendTime.Before(joined) {
log.Printf("Message %+v was sent before room was joined, ignoring", msg.Message)
return nil
}