Skip to content

Commit 1807693

Browse files
committed
fix: reset msgSerial on reconnect after suspension
- Ensure `msgSerial` is reset to `0` when reconnecting from the suspended state. - Added a unit test to verify this behavior.
1 parent 31d1cbf commit 1807693

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

lib/src/main/java/io/ably/lib/transport/ConnectionManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,8 @@ private synchronized void onConnected(ProtocolMessage message) {
12851285
addPendingMessagesToQueuedMessages(true);
12861286
channels.transferToChannelQueue(extractConnectionQueuePresenceMessages());
12871287
}
1288+
} else {
1289+
msgSerial = 0;
12881290
}
12891291

12901292
connection.id = message.connectionId;

lib/src/test/java/io/ably/lib/test/realtime/RealtimeConnectFailTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,24 @@ public void connect_fail_suspended() {
139139
}
140140
}
141141

142+
@Test
143+
public void connect_after_suspend_should_clean_msg_serial() throws AblyException {
144+
ClientOptions opts = createOptions(testVars.keys[0].keyStr);
145+
opts.disconnectedRetryTimeout = Integer.MAX_VALUE;
146+
opts.suspendedRetryTimeout = Integer.MAX_VALUE;
147+
try (AblyRealtime ably = new AblyRealtime(opts)) {
148+
ConnectionWaiter waiter = new ConnectionWaiter(ably.connection);
149+
waiter.waitFor(ConnectionState.connecting);
150+
ably.connection.connectionManager.requestState(ConnectionState.suspended);
151+
waiter.waitFor(ConnectionState.suspended);
152+
ably.connection.connectionManager.msgSerial = 100;
153+
assertEquals("Verify suspended state reached", ConnectionState.suspended, ably.connection.state);
154+
ably.connect();
155+
waiter.waitFor(ConnectionState.connected);
156+
assertEquals(0, ably.connection.connectionManager.msgSerial);
157+
}
158+
}
159+
142160
/**
143161
* Verify that the connection in the disconnected state (after attempts to
144162
* connect to a non-existent ws host) allows an immediate explicit connect

0 commit comments

Comments
 (0)