Description
I have updated LiteCore (3dc6336cf452ecb985e49764dbe20016cbcf028d) to uptake the version-vector update for iOS. A unit test that tests a conflict handler to be called twice due to a conflict when saving a merged doc; the test passed before updating the lite-core.
Failed Test:
How to reproduce:
- Get couchbase-lite-ios, checkout feature/vv-lite-core branch, and update submodules.
- Enable DatabaseTest.m's _testConflictHandlerCalledTwice by removing the underscore and run the test
Log:
https://gist.github.com/pasin/268c3e0566f7a3e0e5ffc278bec004dc
Analysis:
- When the conflict handler is called the first time, the call to set the merged dictionary in this line probably causes the shared key to be updated (I'm not 100% sure as I couldn't see the code that updates the SharedKeys), but without this update, the problem will not occur.
- The merged doc from the first time of conflict handler call is failed to save to due to another conflict. This causes a transaction that saved the merged doc to be aborted. Based on the log, some keys in the SharedKeys table will be reverted as well. However, those reverted keys are still in use by the document being saved in the database.
- When the conflict handler is called the second time, calling toDictionary() on the doc being saved in this line has an error as it tries to access the keys in the SharedKeys that were reverted and released.