mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 08:33:33 -05:00
Add try/catch around all client emissions
This commit is contained in:
parent
d12e056f08
commit
216a977922
4 changed files with 50 additions and 16 deletions
|
@ -71,10 +71,16 @@ module.exports = DocumentUpdaterController =
|
||||||
seen[client.id] = true
|
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"
|
||||||
|
try
|
||||||
client.emit "otUpdateApplied", v: update.v, doc: update.doc
|
client.emit "otUpdateApplied", v: update.v, doc: update.doc
|
||||||
|
catch err
|
||||||
|
logger.warn client_id: client.id, doc_id: doc_id, err: err, "error sending update to sender"
|
||||||
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"
|
||||||
|
try
|
||||||
client.emit "otUpdateApplied", update
|
client.emit "otUpdateApplied", update
|
||||||
|
catch err
|
||||||
|
logger.warn client_id: client.id, doc_id: doc_id, err: err, "error sending update to collaborator"
|
||||||
if Object.keys(seen).length < clientList.length
|
if Object.keys(seen).length < clientList.length
|
||||||
metrics.inc "socket-io.duplicate-clients", 0.1
|
metrics.inc "socket-io.duplicate-clients", 0.1
|
||||||
logger.log doc_id: doc_id, socketIoClients: (client.id for client in clientList), "discarded duplicate clients"
|
logger.log doc_id: doc_id, socketIoClients: (client.id for client in clientList), "discarded duplicate clients"
|
||||||
|
@ -82,7 +88,10 @@ module.exports = DocumentUpdaterController =
|
||||||
_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)
|
||||||
logger.warn err: error, doc_id: doc_id, client_id: client.id, "error from document updater, disconnecting client"
|
logger.warn err: error, doc_id: doc_id, client_id: client.id, "error from document updater, disconnecting client"
|
||||||
|
try
|
||||||
client.emit "otUpdateError", error, message
|
client.emit "otUpdateError", error, message
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
|
catch err
|
||||||
|
logger.warn client_id: client.id, doc_id: doc_id, err: err, cause: error, "error sending error to client"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,10 @@ module.exports = DrainManager =
|
||||||
if !@RECONNECTED_CLIENTS[client.id]
|
if !@RECONNECTED_CLIENTS[client.id]
|
||||||
@RECONNECTED_CLIENTS[client.id] = true
|
@RECONNECTED_CLIENTS[client.id] = true
|
||||||
logger.log {client_id: client.id}, "Asking client to reconnect gracefully"
|
logger.log {client_id: client.id}, "Asking client to reconnect gracefully"
|
||||||
|
try
|
||||||
client.emit "reconnectGracefully"
|
client.emit "reconnectGracefully"
|
||||||
|
catch err
|
||||||
|
logger.warn client_id: client.id, err: err, "error asking client to reconnect gracefully"
|
||||||
drainedCount++
|
drainedCount++
|
||||||
haveDrainedNClients = (drainedCount == N)
|
haveDrainedNClients = (drainedCount == N)
|
||||||
if haveDrainedNClients
|
if haveDrainedNClients
|
||||||
|
|
|
@ -45,29 +45,45 @@ module.exports = Router =
|
||||||
client?.on "error", (err) ->
|
client?.on "error", (err) ->
|
||||||
logger.err { clientErr: err }, "socket.io client error"
|
logger.err { clientErr: err }, "socket.io client error"
|
||||||
if client.connected
|
if client.connected
|
||||||
|
try
|
||||||
client.emit("reconnectGracefully")
|
client.emit("reconnectGracefully")
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
|
catch error
|
||||||
|
logger.warn error: error, cause: err, client_id: client.id, "error telling client to reconnect after error"
|
||||||
|
|
||||||
if settings.shutDownInProgress
|
if settings.shutDownInProgress
|
||||||
|
try
|
||||||
client.emit("connectionRejected", {message: "retry"})
|
client.emit("connectionRejected", {message: "retry"})
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
|
catch error
|
||||||
|
logger.warn error: error, client_id: client.id, message: "retry", "error rejecting client connection"
|
||||||
return
|
return
|
||||||
|
|
||||||
if client? and error?.message?.match(/could not look up session by key/)
|
if client? and error?.message?.match(/could not look up session by key/)
|
||||||
logger.warn err: error, client: client?, session: session?, "invalid session"
|
logger.warn err: error, client: client?, session: session?, "invalid session"
|
||||||
# tell the client to reauthenticate if it has an invalid session key
|
# tell the client to reauthenticate if it has an invalid session key
|
||||||
|
try
|
||||||
client.emit("connectionRejected", {message: "invalid session"})
|
client.emit("connectionRejected", {message: "invalid session"})
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
|
catch error
|
||||||
|
logger.warn error: error, client_id: client.id, message: "invalid session", "error rejecting client connection"
|
||||||
return
|
return
|
||||||
|
|
||||||
if error?
|
if error?
|
||||||
logger.err err: error, client: client?, session: session?, "error when client connected"
|
logger.err err: error, client: client?, session: session?, "error when client connected"
|
||||||
|
try
|
||||||
client?.emit("connectionRejected", {message: "error"})
|
client?.emit("connectionRejected", {message: "error"})
|
||||||
client?.disconnect()
|
client?.disconnect()
|
||||||
|
catch error
|
||||||
|
logger.warn error: error, client_id: client?.id, message: "error", "error rejecting client connection"
|
||||||
return
|
return
|
||||||
|
|
||||||
# send positive confirmation that the client has a valid connection
|
# send positive confirmation that the client has a valid connection
|
||||||
|
try
|
||||||
client.emit("connectionAccepted")
|
client.emit("connectionAccepted")
|
||||||
|
catch error
|
||||||
|
logger.warn error: error, client_id: client.id, "error accepting client connection"
|
||||||
|
return
|
||||||
|
|
||||||
metrics.inc('socket-io.connection')
|
metrics.inc('socket-io.connection')
|
||||||
metrics.gauge('socket-io.clients', io.sockets.clients()?.length)
|
metrics.gauge('socket-io.clients', io.sockets.clients()?.length)
|
||||||
|
|
|
@ -67,7 +67,10 @@ module.exports = WebsocketLoadBalancer =
|
||||||
logger.error {err: error, channel}, "error parsing JSON"
|
logger.error {err: error, channel}, "error parsing JSON"
|
||||||
return
|
return
|
||||||
if message.room_id == "all"
|
if message.room_id == "all"
|
||||||
|
try
|
||||||
io.sockets.emit(message.message, message.payload...)
|
io.sockets.emit(message.message, message.payload...)
|
||||||
|
catch error
|
||||||
|
logger.warn message: message, error: error, "error sending message to clients"
|
||||||
else if message.message is 'clientTracking.refresh' && message.room_id?
|
else if message.message is 'clientTracking.refresh' && message.room_id?
|
||||||
clientList = io.sockets.clients(message.room_id)
|
clientList = io.sockets.clients(message.room_id)
|
||||||
logger.log {channel:channel, message: message.message, room_id: message.room_id, message_id: message._id, socketIoClients: (client.id for client in clientList)}, "refreshing client list"
|
logger.log {channel:channel, message: message.message, room_id: message.room_id, message_id: message._id, socketIoClients: (client.id for client in clientList)}, "refreshing client list"
|
||||||
|
@ -99,7 +102,10 @@ module.exports = WebsocketLoadBalancer =
|
||||||
if !seen[client.id]
|
if !seen[client.id]
|
||||||
seen[client.id] = true
|
seen[client.id] = true
|
||||||
if !(is_restricted_user && message.message not in RESTRICTED_USER_MESSAGE_TYPE_PASS_LIST)
|
if !(is_restricted_user && message.message not in RESTRICTED_USER_MESSAGE_TYPE_PASS_LIST)
|
||||||
|
try
|
||||||
client.emit(message.message, message.payload...)
|
client.emit(message.message, message.payload...)
|
||||||
|
catch error
|
||||||
|
console.log(message: message, client_id: client.id, error: error, "error sending message to client")
|
||||||
cb()
|
cb()
|
||||||
, (err) ->
|
, (err) ->
|
||||||
if err?
|
if err?
|
||||||
|
|
Loading…
Reference in a new issue