Skip to content

Commit ef0ac77

Browse files
committed
Update realtime to use timer to avoid memory leaks on busy tick
1 parent 92ad67b commit ef0ac77

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

lib/realtime.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,12 @@ function clearSocketQueue(queue, socket) {
354354
}
355355

356356
function connectNextSocket() {
357-
isConnectionBusy = false;
358-
if (connectionSocketQueue.length > 0)
359-
startConnection(connectionSocketQueue[0]);
357+
setTimeout(function () {
358+
isConnectionBusy = false;
359+
if (connectionSocketQueue.length > 0) {
360+
startConnection(connectionSocketQueue[0]);
361+
}
362+
}, 1);
360363
}
361364

362365
function interruptConnection(socket, note, user) {
@@ -693,8 +696,11 @@ function operationCallback(socket, operation) {
693696
}
694697
note.tempUsers[userId] = Date.now();
695698
}
696-
// save authorship
697-
note.authorship = models.Note.updateAuthorshipByOperation(operation, userId, note.authorship);
699+
// save authorship - use timer here because it's an O(n) complexity algorithm
700+
setImmediate(function () {
701+
note.authorship = models.Note.updateAuthorshipByOperation(operation, userId, note.authorship);
702+
});
703+
}
698704

699705
function updateHistory(userId, note, time) {
700706
var noteId = note.alias ? note.alias : LZString.compressToBase64(note.id);

0 commit comments

Comments
 (0)