|
@@ -4,6 +4,7 @@ redis = require("redis-sharelatex")
|
|
|
rclient = redis.createClient(settings.redis.documentupdater)
|
|
rclient = redis.createClient(settings.redis.documentupdater)
|
|
|
SafeJsonParse = require "./SafeJsonParse"
|
|
SafeJsonParse = require "./SafeJsonParse"
|
|
|
EventLogger = require "./EventLogger"
|
|
EventLogger = require "./EventLogger"
|
|
|
|
|
+metrics = require "metrics-sharelatex"
|
|
|
|
|
|
|
|
MESSAGE_SIZE_LOG_LIMIT = 1024 * 1024 # 1Mb
|
|
MESSAGE_SIZE_LOG_LIMIT = 1024 * 1024 # 1Mb
|
|
|
|
|
|
|
@@ -31,13 +32,20 @@ module.exports = DocumentUpdaterController =
|
|
|
logger.debug {message}, "got health check message in applied ops channel"
|
|
logger.debug {message}, "got health check message in applied ops channel"
|
|
|
|
|
|
|
|
_applyUpdateFromDocumentUpdater: (io, doc_id, update) ->
|
|
_applyUpdateFromDocumentUpdater: (io, doc_id, update) ->
|
|
|
- for client in io.sockets.clients(doc_id)
|
|
|
|
|
|
|
+ clientList = io.sockets.clients(doc_id)
|
|
|
|
|
+ seen = {}
|
|
|
|
|
+ # send messages only to unique clients (due to duplicate entries in io.sockets.clients)
|
|
|
|
|
+ for client in clientList when not seen[client.id]
|
|
|
|
|
+ seen[client.id] = true
|
|
|
if client.id == update.meta.source
|
|
if client.id == update.meta.source
|
|
|
logger.log doc_id: doc_id, version: update.v, source: update.meta?.source, "distributing update to sender"
|
|
logger.log doc_id: doc_id, version: update.v, source: update.meta?.source, "distributing update to sender"
|
|
|
client.emit "otUpdateApplied", v: update.v, doc: update.doc
|
|
client.emit "otUpdateApplied", v: update.v, doc: update.doc
|
|
|
else if !update.dup # Duplicate ops should just be sent back to sending client for acknowledgement
|
|
else if !update.dup # Duplicate ops should just be sent back to sending client for acknowledgement
|
|
|
logger.log doc_id: doc_id, version: update.v, source: update.meta?.source, client_id: client.id, "distributing update to collaborator"
|
|
logger.log doc_id: doc_id, version: update.v, source: update.meta?.source, client_id: client.id, "distributing update to collaborator"
|
|
|
client.emit "otUpdateApplied", update
|
|
client.emit "otUpdateApplied", update
|
|
|
|
|
+ if Object.keys(seen).length < clientList.length
|
|
|
|
|
+ metrics.inc "socket-io.duplicate-clients", 0.1
|
|
|
|
|
+ logger.log doc_id: doc_id, socketIoClients: (client.id for client in clientList), "discarded duplicate clients"
|
|
|
|
|
|
|
|
_processErrorFromDocumentUpdater: (io, doc_id, error, message) ->
|
|
_processErrorFromDocumentUpdater: (io, doc_id, error, message) ->
|
|
|
for client in io.sockets.clients(doc_id)
|
|
for client in io.sockets.clients(doc_id)
|
|
@@ -46,5 +54,3 @@ module.exports = DocumentUpdaterController =
|
|
|
client.disconnect()
|
|
client.disconnect()
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|