yorkie-js-sdk
yorkie-js-sdk copied to clipboard
Bug when performing multiple `sync()`
What happened: When performing multiple 'pushpull' requests, the SDK doesn't work correctly. For example, the following test case fails: https://github.com/yorkie-team/yorkie-js-sdk/blob/394c061cdac97d47508fee8178ab64874641a580/test/integration/document_test.ts#L57-L93
Anything else we need to know?:
In the test code, four changes are generated:
- change (serverSeq 1): d1 update
root['k1'] = [1, 2] - change (serverSeq 2): c1 initial presence (within c1.attach)
- change (serverSeq 3): c2 initial presence (within c2.attach)
- change (serverSeq 4): d1 update
root['k1'].push(3)
When c2.sync() is called, it sends two pushpull requests with checkpoint{clientSeq: 1, serverSeq: 3}. The server responds with change (serverSeq 4), then c2 applies the same change twice, resulting in [1, 2, 3, 3] not [1, 2, 3].
(When multiple changes are pushed, the server handles it to prevent duplicate changes from being stored. However, the client needs to handle it when processing the response.)
I think one of the solution is enqueuing 'sync' requests. The next request should be sent after receiving the response to update the server sequence.
Environment:
- Operating system:
- Browser and version:
- Yorkie version (use
yorkie version):0.4.5 - Yorkie JS SDK version:
0.4.5