Skip to content

Commit

Permalink
Merge pull request #44 from conversation/16370-dont-reap-docs-with-ne…
Browse files Browse the repository at this point in the history
…wly-active-listeners

Check for late addition of listeners before reaping doc
  • Loading branch information
nickbrowne authored Feb 25, 2024
2 parents d8e574a + f70860a commit fd0c935
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/server/model.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,16 @@ module.exports = Model = (db, options) ->
clearTimeout doc.reapTimer
doc.reapTimer = reapTimer = setTimeout ->
tryWriteSnapshot docName, ->
# If the reaping timeout has been refreshed while we're writing the snapshot, or if we're
# in the middle of applying an operation, don't reap.
delete docs[docName] if docs[docName].reapTimer is reapTimer and doc.opQueue.busy is false
# If the document has newly added listeners, or the reaping timeout has been refreshed
# while we're writing the snapshot, or if we're in the middle of applying an operation,
# don't reap.
#
# Listeners can appear on the document "late" if they were in the middle of the catchup
# phase when `nextTick` was first called above.
if doc.eventEmitter.listeners('op').length == 0 and
docs[docName].reapTimer is reapTimer and
doc.opQueue.busy is false
delete docs[docName]
, options.reapTime

tryWriteSnapshot = (docName, callback) ->
Expand Down

0 comments on commit fd0c935

Please sign in to comment.