Skip to content

Commit

Permalink
Merge pull request #977 from ably/fix-reattaching-detached-channels
Browse files Browse the repository at this point in the history
fix: prevent reattaching of detached channels
  • Loading branch information
ttypic authored Nov 23, 2023
2 parents 78a7137 + b0e89fc commit 654c3b1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/src/main/java/io/ably/lib/realtime/AblyRealtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public void transferToChannels(List<ConnectionManager.QueuedMessage> queuedMessa

for (Map.Entry<String, Channel> channelEntry : map.entrySet()) {
Channel channel = channelEntry.getValue();
if (channel.state == ChannelState.attaching || channel.state == ChannelState.attached || channel.state == ChannelState.suspended) {
if (channel.state.isReattachable()) {
Log.d(TAG, "reAttach(); channel = " + channel.name);

if (channelQueueMap.containsKey(channel.name)){
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/java/io/ably/lib/realtime/ChannelBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ public void run() {
/* State changes provoked by ConnectionManager state changes. */

public void setConnected(boolean reattachOnResumeFailure) {
if (reattachOnResumeFailure){
if (reattachOnResumeFailure && state.isReattachable()){
attach(true,null);
} else if (state == ChannelState.suspended) {
/* (RTL3d) If the connection state enters the CONNECTED state, then
Expand Down
4 changes: 4 additions & 0 deletions lib/src/main/java/io/ably/lib/realtime/ChannelState.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ public enum ChannelState {
public ChannelEvent getChannelEvent() {
return event;
}

public boolean isReattachable() {
return this == ChannelState.attaching || this == ChannelState.attached || this == ChannelState.suspended;
}
}

0 comments on commit 654c3b1

Please sign in to comment.