Skip to content

Commit

Permalink
Revert reconnect optimizations which introduced regressions. Fixes #3161
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Feb 12, 2019
1 parent 7de9894 commit 0f967ad
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 46 deletions.
27 changes: 2 additions & 25 deletions assets/js/phoenix.js
Expand Up @@ -840,7 +840,6 @@ export class Socket {
this.flushSendBuffer()
this.reconnectTimer.reset()
this.resetHeartbeat()
this.resetChannelTimers()
this.stateChangeCallbacks.open.forEach( callback => callback() )
}

Expand Down Expand Up @@ -989,15 +988,6 @@ export class Socket {
}
})
}

/**
* @private
*/
resetChannelTimers() {
this.channels.forEach(channel => {
channel.rejoinTimer.restart()
})
}
}


Expand Down Expand Up @@ -1358,31 +1348,18 @@ class Timer {

reset(){
this.tries = 0
this.clearTimer()
}

restart(){
const processing = this.timer !== null
this.reset()
if (processing){
this.scheduleTimeout()
}
clearTimeout(this.timer)
}

/**
* Cancels any previous scheduleTimeout and schedules callback
*/
scheduleTimeout(){
this.clearTimer()
clearTimeout(this.timer)

this.timer = setTimeout(() => {
this.tries = this.tries + 1
this.callback()
}, this.timerCalc(this.tries + 1))
}

clearTimer() {
clearTimeout(this.timer)
this.timer = null
}
}
19 changes: 0 additions & 19 deletions assets/test/socket_test.js
Expand Up @@ -605,25 +605,6 @@ describe("onConnOpen", () => {
assert.ok(spy.calledOnce)
})

it("resets all channel timers and schedules a timeout if the timer was in progress", () => {
const channel = socket.channel("topic", {})
const channel2 = socket.channel("topic2", {})

channel.rejoinTimer.tries = 1
channel2.rejoinTimer.tries = 2
channel2.rejoinTimer.scheduleTimeout()

assert.equal(channel.rejoinTimer.timer, null)
assert.notEqual(channel2.rejoinTimer.timer, null)

socket.onConnOpen()

assert.equal(channel.rejoinTimer.tries, 0)
assert.equal(channel2.rejoinTimer.tries, 0)
assert.equal(channel.rejoinTimer.timer, null)
assert.notEqual(channel2.rejoinTimer.timer, null)
})

it("triggers onOpen callback", () => {
const spy = sinon.spy()

Expand Down

0 comments on commit 0f967ad

Please sign in to comment.