Skip to content

Commit 77ba73c

Browse files
author
Daniel Rees
authored
Prevent entering a rejoin loop if channel leaves before joined (#64)
1 parent e646990 commit 77ba73c

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/main/kotlin/org/phoenixframework/Channel.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ class Channel(
320320
// If attempting a rejoin during a leave, then reset, cancelling the rejoin
321321
this.rejoinTimer.reset()
322322

323+
// Prevent entering a rejoin loop if leaving a channel before joined
324+
this.joinPush.cancelTimeout()
325+
323326
// Now set the state to leaving
324327
this.state = State.LEAVING
325328

src/main/kotlin/org/phoenixframework/Push.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class Push(
177177
}
178178

179179
/** Cancels any ongoing timeout task */
180-
private fun cancelTimeout() {
180+
internal fun cancelTimeout() {
181181
this.timeoutTask?.cancel()
182182
this.timeoutTask = null
183183
}

src/test/kotlin/org/phoenixframework/ChannelTest.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,19 @@ class ChannelTest {
314314
assertThat(channel.state).isEqualTo(Channel.State.JOINED)
315315
}
316316

317+
318+
@Test
319+
internal fun `does not enter rejoin loop if leave is called before joined`() {
320+
socket.connect()
321+
this.receiveSocketOpen()
322+
323+
channel.join()
324+
channel.leave()
325+
326+
fakeClock.tick(channel.timeout * 4)
327+
verify(socket, times(2)).push(any(), any(), any(), any(), any())
328+
}
329+
317330
/* End TimeoutBehavior */
318331
}
319332

@@ -1042,6 +1055,7 @@ class ChannelTest {
10421055
channel.leave()
10431056
assertThat(channel.state).isEqualTo(Channel.State.CLOSED)
10441057
}
1058+
10451059
/* End Leave */
10461060
}
10471061

0 commit comments

Comments
 (0)