Skip to content

Commit

Permalink
Fixed race condition while accessing state, updated code as per spec
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Dec 5, 2023
1 parent e4ef0ce commit 1b7a72d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 0 additions & 1 deletion ably/proto_presence_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,6 @@ func Test_internal_presencemap_RTP17(t *testing.T) {

in <- &ably.ProtocolMessage{
Action: ably.ActionAttached,
Flags: ably.FlagResumed,
Channel: channel.Name,
}

Expand Down
10 changes: 6 additions & 4 deletions ably/realtime_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,10 +797,12 @@ func (c *RealtimeChannel) notify(msg *protocolMessage) {
if msg.Flags != 0 {
c.setModes(channelModeFromFlag(msg.Flags))
}
// RTL12
if c.state == ChannelStateAttached && !msg.Flags.Has(flagResumed) {
c.emitErrorUpdate(newErrorFromProto(msg.Error), false) // RTL12
c.Presence.onAttach(msg, false)

if c.State() == ChannelStateAttached {
if !msg.Flags.Has(flagResumed) { // RTL12
c.Presence.onAttach(msg, true)
c.emitErrorUpdate(newErrorFromProto(msg.Error), false)
}
} else {
c.Presence.onAttach(msg, true)
c.setState(ChannelStateAttached, newErrorFromProto(msg.Error), msg.Flags.Has(flagResumed))
Expand Down

0 comments on commit 1b7a72d

Please sign in to comment.