From 97e382e5d2c0a7b57d9420d974318bb8cf7dc45e Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 16 Nov 2021 16:05:28 -0500 Subject: [PATCH] PadMessageHandler: Move USER_CHANGES processing inside `try` This improves the accuracy of the timing stats, and it simplifies error handling. --- src/node/handler/PadMessageHandler.js | 32 ++++++--------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index 72a5e812a..3f9cbfaba 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -560,24 +560,6 @@ const handleUserChanges = async (socket, message) => { // This one's no longer pending, as we're gonna process it now stats.counter('pendingEdits').dec(); - const {data: {baseRev, apool, changeset}} = message; - - // Make sure all required fields are present - if (baseRev == null) { - messageLogger.warn('Dropped message, USER_CHANGES Message has no baseRev!'); - return; - } - - if (apool == null) { - messageLogger.warn('Dropped message, USER_CHANGES Message has no apool!'); - return; - } - - if (changeset == null) { - messageLogger.warn('Dropped message, USER_CHANGES Message has no changeset!'); - return; - } - // The client might disconnect between our callbacks. We should still // finish processing the changeset, so keep a reference to the session. const thisSession = sessioninfos[socket.id]; @@ -590,16 +572,16 @@ const handleUserChanges = async (socket, message) => { return; } - const wireApool = (new AttributePool()).fromJsonable(apool); - // Measure time to process edit const stopWatch = stats.timer('edits').start(); - - // get the pad - const pad = await padManager.getPad(thisSession.padId); - - // create the changeset try { + const {data: {baseRev, apool, changeset}} = message; + if (baseRev == null) throw new Error('missing baseRev'); + if (apool == null) throw new Error('missing apool'); + if (changeset == null) throw new Error('missing changeset'); + const wireApool = (new AttributePool()).fromJsonable(apool); + const pad = await padManager.getPad(thisSession.padId); + // Verify that the changeset has valid syntax and is in canonical form Changeset.checkRep(changeset);