diff --git a/lib/realtime.js b/lib/realtime.js index 1269e4116..66d606fa4 100644 --- a/lib/realtime.js +++ b/lib/realtime.js @@ -363,13 +363,6 @@ function connectNextSocket () { }, 1) } -function interruptConnection (socket, noteId, socketId) { - if (notes[noteId]) delete notes[noteId] - if (users[socketId]) delete users[socketId] - if (socket) { clearSocketQueue(connectionSocketQueue, socket) } else { connectionSocketQueue.shift() } - connectNextSocket() -} - function checkViewPermission (req, note) { if (note.permission === 'private') { if (req.user && req.user.logged_in && req.user.id === note.owner) { return true } else { return false } @@ -386,13 +379,8 @@ let isDisconnectBusy = false const disconnectSocketQueue = [] function finishConnection (socket, noteId, socketId) { - // if no valid info provided will drop the client - if (!socket || !notes[noteId] || !users[socketId]) { - return interruptConnection(socket, noteId, socketId) - } // check view permission if (!checkViewPermission(socket.request, notes[noteId])) { - interruptConnection(socket, noteId, socketId) return failConnection(403, 'connection forbidden', socket) } const note = notes[noteId] @@ -460,6 +448,13 @@ function startConnection (socket) { }, include }).then(function (note) { + // if client disconnected while we waited for the note, disconnect() cleaned up users[socket.id] + if (!users[socket.id]) { + clearSocketQueue(connectionSocketQueue, socket) + connectNextSocket() + return + } + if (!note) { return failConnection(404, 'note not found', socket) } diff --git a/public/docs/release-notes.md b/public/docs/release-notes.md index 2ec84b72c..34fccdd0c 100644 --- a/public/docs/release-notes.md +++ b/public/docs/release-notes.md @@ -10,6 +10,9 @@ You now need Node 16 to run HedgeDoc. We don't support more recent versions of N - Allow setting of `documentMaxLength` via `CMD_DOCUMENT_MAX_LENGTH` environment variable. - Add dedicated healthcheck endpoint at /_health that is less resource intensive than /status. +### Bugfixes +- Fix that permission errors can break existing connections to a note, causing inconsistent note content and changes not being saved + ## 1.9.7 2023-02-19 ### Bugfixes