diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index 214571044..84ec9b5c1 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -1124,20 +1124,25 @@ async function handleClientReady(socket, message, authorID) { if (sessionInfo == null) return; // get the authorname & colorId - const author = sessionInfo.author; - const cached = historicalAuthorData[author]; + const authorId = sessionInfo.author; + // The authorId of this other user might be unknown if the other user just connected and has + // not yet sent a CLIENT_READY message. + if (authorId == null) return; // reuse previously created cache of author's data - let authorInfo = cached ? cached : (await authorManager.getAuthor(author)); + const authorInfo = historicalAuthorData[authorId] || await authorManager.getAuthor(authorId); + if (authorInfo == null) { + messageLogger.error( + `Author ${authorId} connected via socket.io session ${roomSocket.id} is missing from ` + + 'the global author database. This should never happen because the author ID is ' + + 'generated by the same code that adds the author to the database.'); + // Don't bother telling the new user about this mystery author. + return; + } // default fallback color to use if authorInfo.colorId is null const defaultColor = '#daf0b2'; - if (!authorInfo) { - console.warn('handleClientReady(): no authorInfo parameter was received. Default values are going to be used. See issue #3612. This can be caused by a user clicking undo after clearing all authorship colors see #2802'); - authorInfo = {}; - } - // For some reason sometimes name isn't set // Catch this issue here and use a fixed name. if (!authorInfo.name) { @@ -1162,7 +1167,7 @@ async function handleClientReady(socket, message, authorID) { colorId: authorInfo.colorId, name: authorInfo.name, userAgent: 'Anonymous', - userId: author, + userId: authorId, }, }, };