Explorar o código

Don't clean up a documents event listener until after the socket has disconnected on error

James Allen %!s(int64=10) %!d(string=hai) anos
pai
achega
345d38c28d

+ 2 - 2
services/web/public/coffee/ide/connection/ConnectionManager.coffee

@@ -52,6 +52,7 @@ define [], () ->
 				"force new connection": true
 
 			@ide.socket.on "connect", () =>
+				sl_console.log "[socket.io connect] Connected"
 				@connected = true
 				@ide.pushEvent("connected")
 
@@ -61,8 +62,6 @@ define [], () ->
 					if @$scope.state.loading
 						@$scope.state.load_progress = 70
 
-				sl_console.log "[socket.io connect] Connected"
-
 				setTimeout(() =>
 					@joinProject()
 				, 100)
@@ -75,6 +74,7 @@ define [], () ->
 
 
 			@ide.socket.on 'disconnect', () =>
+				sl_console.log "[socket.io disconnect] Disconnected"
 				@connected = false
 				@ide.pushEvent("disconnected")
 

+ 7 - 2
services/web/public/coffee/ide/editor/Document.coffee

@@ -198,6 +198,7 @@ define [
 					@leave()
 
 		_onDisconnect: () ->
+			sl_console.log '[onDisconnect] disconnecting'
 			@connected = false
 			@joined = false
 			@doc?.updateConnectionState "disconnected"
@@ -253,7 +254,7 @@ define [
 			else
 				# It's possible that this instance has error, and the doc has been reloaded.
 				# This creates a new instance in Document.openDoc with the same id. We shouldn't
-				# clear it because it's not use.
+				# clear it because it's not this instance.
 				sl_console.log "[_cleanUp] New instance of (#{@doc_id}) created. Not removing"
 			@_unBindFromEditorEvents()
 			@_unBindFromSocketEvents()
@@ -296,5 +297,9 @@ define [
 			console.error "ShareJS error", error, meta
 			ga?('send', 'event', 'error', "shareJsError", "#{error.message} - #{@ide.socket.socket.transport.name}" )
 			@doc?.clearInflightAndPendingOps()
-			@_cleanUp()
 			@trigger "error", error, meta
+			# The clean up should run after the error is triggered because the error triggers a
+			# disconnect. If we run the clean up first, we remove our event handlers and miss
+			# the disconnect event, which means we try to leaveDoc when the connection comes back.
+			# This could intefere with the new connection of a new instance of this document.
+			@_cleanUp()