Skip to content

Commit

Permalink
Fixed goroutine issue for entering internal presence members
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Nov 21, 2023
1 parent f0e50d0 commit f7afecd
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions ably/realtime_presence.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,7 @@ func syncSerial(msg *protocolMessage) (noChannelSerial bool, syncSequenceId stri
return false, syncSequenceId, syncCursor
}

func (pres *RealtimePresence) enterMembersFromInternalPresenceMap() {
pres.mtx.Lock()
internalMembers := make([]*PresenceMessage, len(pres.internalMembers))
indexCounter := 0
for _, member := range pres.internalMembers {
internalMembers[indexCounter] = member
indexCounter = indexCounter + 1
}
pres.mtx.Unlock()
func (pres *RealtimePresence) enterMembers(internalMembers []*PresenceMessage) {
for _, member := range internalMembers {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
// RTP17g
Expand Down Expand Up @@ -183,7 +175,13 @@ func (pres *RealtimePresence) onAttach(msg *protocolMessage, isAttachWithoutMess
pres.queue.Flush() // RTP5b
// RTP17f
if isAttachWithoutMessageLoss {
go pres.enterMembersFromInternalPresenceMap()
internalMembers := make([]*PresenceMessage, len(pres.internalMembers))
indexCounter := 0
for _, member := range pres.internalMembers {
internalMembers[indexCounter] = member
indexCounter = indexCounter + 1
}
go pres.enterMembers(internalMembers)
}
}

Expand Down

0 comments on commit f7afecd

Please sign in to comment.