Merge pull request #3487 from overleaf/bg-shut-down-connection-manager

shut down connection manager on out of sync

GitOrigin-RevId: e191ed62a49c72e8b8ed8c9ba57ed6e0b3606abe
This commit is contained in:
Brian Gough 2020-12-14 09:34:57 +00:00 committed by Copybot
parent 9a1ef37991
commit c446f7712c
2 changed files with 20 additions and 7 deletions

View file

@ -72,6 +72,7 @@ export default (ConnectionManager = (function() {
this.connected = false this.connected = false
this.userIsInactive = false this.userIsInactive = false
this.gracefullyReconnecting = false this.gracefullyReconnecting = false
this.shuttingDown = false
this.joinProjectRetryInterval = this.JOIN_PROJECT_RETRY_INTERVAL this.joinProjectRetryInterval = this.JOIN_PROJECT_RETRY_INTERVAL
@ -99,7 +100,11 @@ export default (ConnectionManager = (function() {
}) })
document.querySelector('body').addEventListener('click', e => { document.querySelector('body').addEventListener('click', e => {
if (!this.connected && e.target.id !== 'try-reconnect-now-button') { if (
!this.shuttingDown &&
!this.connected &&
e.target.id !== 'try-reconnect-now-button'
) {
// user is editing, try to reconnect // user is editing, try to reconnect
return this.tryReconnectWithRateLimit() return this.tryReconnectWithRateLimit()
} }
@ -235,7 +240,8 @@ export default (ConnectionManager = (function() {
if (!this.$scope.connection.state.match(/^waiting/)) { if (!this.$scope.connection.state.match(/^waiting/)) {
if ( if (
!this.$scope.connection.forced_disconnect && !this.$scope.connection.forced_disconnect &&
!this.userIsInactive !this.userIsInactive &&
!this.shuttingDown
) { ) {
this.startAutoReconnectCountdown() this.startAutoReconnectCountdown()
} else { } else {
@ -451,8 +457,12 @@ Something went wrong connecting to your project. Please refresh if this continue
return this.tryReconnect() return this.tryReconnect()
} }
disconnect() { disconnect(options) {
if (this.ide.socket.socket && !this.ide.socket.socket.connected) { if (options && options.permanent) {
sl_console.log('[disconnect] shutting down ConnectionManager')
this.updateConnectionManagerState('inactive')
this.shuttingDown = true // prevent reconnection attempts
} else if (this.ide.socket.socket && !this.ide.socket.socket.connected) {
sl_console.log( sl_console.log(
'[socket.io] skipping disconnect because socket.io has not connected' '[socket.io] skipping disconnect because socket.io has not connected'
) )
@ -548,7 +558,11 @@ Something went wrong connecting to your project. Please refresh if this continue
tryReconnect() { tryReconnect() {
sl_console.log('[ConnectionManager] tryReconnect') sl_console.log('[ConnectionManager] tryReconnect')
if (this.connected || this.$scope.connection.reconnecting) { if (
this.connected ||
this.shuttingDown ||
this.$scope.connection.reconnecting
) {
return return
} }
this.updateConnectionManagerState('reconnecting') this.updateConnectionManagerState('reconnecting')

View file

@ -316,8 +316,7 @@ export default (EditorManager = (function() {
// Do not re-join after re-connecting. // Do not re-join after re-connecting.
sharejs_doc.leaveAndCleanUp() sharejs_doc.leaveAndCleanUp()
this.ide.connectionManager.disconnect({ permanent: true })
this.ide.socket.disconnect()
this.ide.reportError(error, meta) this.ide.reportError(error, meta)
// Tell the user about the error state. // Tell the user about the error state.