diff options
author | Marcel Klehr <mklehr@gmx.net> | 2012-09-28 05:43:47 -0700 |
---|---|---|
committer | Marcel Klehr <mklehr@gmx.net> | 2012-09-28 05:43:47 -0700 |
commit | 3578e36616f8882827eb4de160e703fd74becec7 (patch) | |
tree | c7d37bbc29a37f801f1ca56ac103c360cf7b1601 /src/node | |
parent | 49799bfa97b6ffd2529169b5486bded5f19d655b (diff) | |
parent | 7aaef01346ca61d7778c15f9b35f72713065f297 (diff) | |
download | etherpad-lite-3578e36616f8882827eb4de160e703fd74becec7.zip |
Merge pull request #1025 from amtep/develop
Fix race condition and a stack error caused by too old changesets
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/handler/PadMessageHandler.js | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index 913433b0..8a5a92bb 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -465,6 +465,9 @@ function handleUserChanges(client, message) var baseRev = message.data.baseRev; var wireApool = (new AttributePool()).fromJsonable(message.data.apool); var changeset = message.data.changeset; + // The client might disconnect between our callbacks. We should still + // finish processing the changeset, so keep a reference to the session. + var thisSession = sessioninfos[client.id]; var r, apool, pad; @@ -472,7 +475,7 @@ function handleUserChanges(client, message) //get the pad function(callback) { - padManager.getPad(sessioninfos[client.id].padId, function(err, value) + padManager.getPad(thisSession.padId, function(err, value) { if(ERR(err, callback)) return; pad = value; @@ -525,7 +528,11 @@ function handleUserChanges(client, message) if(ERR(err, callback)) return; changeset = Changeset.follow(c, changeset, false, apool); - callback(null); + if ((r - baseRev) % 200 == 0) { // don't let the stack get too deep + async.nextTick(callback); + } else { + callback(null); + } }); }, //use the callback of the series function @@ -545,9 +552,7 @@ function handleUserChanges(client, message) return; } - var thisAuthor = sessioninfos[client.id].author; - - pad.appendRevision(changeset, thisAuthor); + pad.appendRevision(changeset, thisSession.author); var correctionChangeset = _correctMarkersInPad(pad.atext, pad.pool); if (correctionChangeset) { |