peer-base / js-delta-crdts

Delta State-based CRDTs in Javascript
192 stars 16 forks source link

Fix infinite loop in RGA push() when last edge points to null #11

Closed dirkmc closed 5 years ago

dirkmc commented 5 years ago

The problem is that msgpack-lite encodes { "id": undefined } as { "id": null }. See https://github.com/kawanet/msgpack-lite/issues/71

After adding a value to the RGA, the edge Map looks something like:

{
  null => "cjmi30qvl00013h5ph5d0p9a6"
  "cjmi30qvl00013h5ph5d0p9a6" => undefined
}

But after encoding it and then decoding it, it becomes:

{
  null => "cjmi30qvl00013h5ph5d0p9a6"
  "cjmi30qvl00013h5ph5d0p9a6" => null
}

So when we call RGA push(), the following lines in the push() method loop forever (because last is null instead of undefined:

      let last = null
      while (edges.has(last) && (edges.get(last) !== undefined)) {
        last = edges.get(last)
      }
pgte commented 5 years ago

@dirkmc thanks!

Fix landed in version 0.3.2.