mizzao / meteor-sharejs

Meteor smart package for transparently adding ShareJS editors to an app
MIT License
225 stars 53 forks source link

broken with multiple app instances? #79

Closed yeeking closed 8 years ago

yeeking commented 8 years ago

Hello folks!

We have come across a problem with meteor-sharejs (actually sharejs) when it runs in a cluster configuration with multiple app instances.

Problem

In share.js, which is pulled in from here (according to the package.js file):

https://github.com/mizzao/ShareJS/tarball/05b625ea1e7f7f27bd13ba7ed05102b38dd175e5

there are two lines

this.version++;

which dictate the _id for an op. This does not work if you have two app instances (e.g. running in containers in meteor galaxy) as two connected users on the same doc, each conntected to a different instance, will generate the same version number and mongo will not accept the ops since they have have the same _id.

How to see the problem in action:

Startup your own mongo server.

Run two app instances: MONGO_URL=mongodb://localhost:27017/databasename meteor --port=3000 MONGO_URL=mongodb://localhost:27017/databasename meteor --port=3001

then try to edit the same document with two different users, one connected to each app instance, the first user is blocked from editing once the second user joins. This does not happen if they are in the same app instance. There is a server error:

W20160720-16:48:00.696(1)? (STDERR) failed to save op [object Object] for qTueDuoQfkNNHrBZL: MongoError: E11000 duplicate key error index: codecircle_live.ops.$_id_ dup key: { : { doc: "qTueDuoQfkNNHrBZL", v: 36 } }

The v is generated in the share.js file.

Thanks!

Matthew

yeeking commented 8 years ago

Hello again,

After a bit more digging, this is a known aspect of sharejs 0.6, i.e. it does not work across a cluster.

https://josephg.com/blog/sharejs/

Anyone tested 0.7 yet? We can potentially provide some developer time to work on this...

cheers

Matthew