-
Notifications
You must be signed in to change notification settings - Fork 218
Description
A Node.js application using Automerge 3 had an issue with the first synchronization of a document after a fresh install. The server had a document state, the application previously had the document synched, but after reinstall and wiping the local doc repo, it had an issue on that first sync.
The backtrace is
panicked at automerge/src/op_set2/change/batch.rs:817:47:
called `Result::unwrap()` on an `Err` value: PatchLogMismatch
Stack:
Error
at /snapshot/project/dist/bundle.js:132598:19
at automerge_wasm.wasm.__wbg_new_8a6f238a6ece86ea externref shim (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[2851]:0x2028b3)
at automerge_wasm.wasm.console_error_panic_hook::hook::h6a5a252dd7c481c3 (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[1014]:0x1af90b)
at automerge_wasm.wasm.core::ops::function::Fn::call::h9136cf91e933f56c (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[3159]:0x203ac6)
at automerge_wasm.wasm.std::panicking::rust_panic_with_hook::h4501cceb7dbe383d (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[1792]:0x1ec9da)
at automerge_wasm.wasm.std::panicking::begin_panic_handler::{{closure}}::hc2b9d3fc26dda7f9 (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[1918]:0x1f23eb)
at automerge_wasm.wasm.std::sys::backtrace::__rust_end_short_backtrace::hf6a83a0a2155b9c0 (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[3139]:0x203a10)
at automerge_wasm.wasm.rust_begin_unwind (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[2527]:0x20006c)
at automerge_wasm.wasm.core::panicking::panic_fmt::h619600efce2da276 (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[2528]:0x200098)
at automerge_wasm.wasm.core::result::unwrap_failed::h4ec8ebc0cd29f54b (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[2009]:0x1f582b)
error receiving message {
err: RuntimeError: unreachable
at automerge_wasm.wasm.__rust_start_panic (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[3181]:0x203b4e)
at automerge_wasm.wasm.rust_panic (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[2959]:0x20312d)
at automerge_wasm.wasm.std::panicking::rust_panic_with_hook::h4501cceb7dbe383d (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[1792]:0x1eca05)
at automerge_wasm.wasm.std::panicking::begin_panic_handler::{{closure}}::hc2b9d3fc26dda7f9 (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[1918]:0x1f23eb)
at automerge_wasm.wasm.std::sys::backtrace::__rust_end_short_backtrace::hf6a83a0a2155b9c0 (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[3139]:0x203a10)
at automerge_wasm.wasm.rust_begin_unwind (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[2527]:0x20006c)
at automerge_wasm.wasm.core::panicking::panic_fmt::h619600efce2da276 (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[2528]:0x200098)
at automerge_wasm.wasm.core::result::unwrap_failed::h4ec8ebc0cd29f54b (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[2009]:0x1f582b)
at automerge_wasm.wasm.automerge::op_set2::change::batch::BatchApply::apply::he7b8d1985f6144fd (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[77]:0x28713)
at automerge_wasm.wasm.automerge::automerge::Automerge::apply_changes_log_patches::h07ee474e737d88a2 (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[144]:0xaa84b),
message: {
type: 'sync',
targetId: 'peer-i53btkkjg',
data: <Buffer 43 01 93 a9 cb 5b 57 f4 be 48 e7 76 b5 64 95 5f f9 4d ce 5d b1 e3 e2 99 8c a7 ab fe ee ae 58 78 38 fa 00 01 00 9e ab 01 fa 88 01 0a 07 d6 38 80 a5 ca ... 186287 more bytes>,
documentId: '24JBohNtEUZLBmM8LggBxrhRbZcQ',
senderId: 'peer-bwhxep98a'
}
}
Error: recursive use of an object detected which would lead to unsafe aliasing in rust
at /snapshot/project/dist/bundle.js:132773:13
at automerge_wasm.wasm.wasm_bindgen::throw_str::h1bc716d03d128d59 (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[3068]:0x2036df)
at automerge_wasm.wasm.wasm_bindgen::__rt::borrow_fail::h9c5a4b50ba1257b0 (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[3070]:0x2036fb)
at automerge_wasm.wasm.automerge_getHeads (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[1844]:0x1ef167)
at automerge_wasm.wasm.automerge_getHeads externref shim (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[2930]:0x202f68)
at _Automerge.getHeads (/snapshot/project/dist/bundle.js:132145:27)
at Object.getHeads (/snapshot/project/dist/bundle.js:121167:38)
at #checkForChanges (/snapshot/project/dist/bundle.js:128581:52)
at /snapshot/project/dist/bundle.js:128525:32
at Actor.update (/snapshot/project/dist/bundle.js:123415:32)
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
Error: recursive use of an object detected which would lead to unsafe aliasing in rust
at /snapshot/project/dist/bundle.js:132773:13
at automerge_wasm.wasm.wasm_bindgen::throw_str::h1bc716d03d128d59 (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[3068]:0x2036df)
at automerge_wasm.wasm.wasm_bindgen::__rt::borrow_fail::h9c5a4b50ba1257b0 (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[3070]:0x2036fb)
at automerge_wasm.wasm.automerge_save (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[1619]:0x1e3122)
at automerge_wasm.wasm.automerge_save externref shim (wasm://wasm/automerge_wasm.wasm-0096ca9a:wasm-function[2927]:0x202f2f)
at _Automerge.save (/snapshot/project/dist/bundle.js:132019:27)
at Object.save (/snapshot/project/dist/bundle.js:120981:29)
at #saveTotal (/snapshot/project/dist/bundle.js:130078:47)
at StorageSubsystem.saveDoc (/snapshot/project/dist/bundle.js:130037:32)
at /snapshot/project/dist/bundle.js:130699:44
This doesn't occur on every fresh install. The error also doesn't reoccur if I restart the app. I don't have steps to reproduce this error in a simple app yet, but if I update this issue if I can reproduce it reliably.
The main thing I want to point out is that the function migrate_actors can return an error, but the caller in BatchApply unwraps the return value of migrate_actors. That doesn't look safe. Is there something the library can do in case migrate_actors returns an error other than panic?
Separately from this, what could cause PatchLogMismatch to be returned? I think it would be self.actors.get(i), others.get(i) match (Some(a), Some(b)) if b > a, but what does that imply? Could it be due to the server sending a patch op to the application but the patch was intended for the previous instance of the app, and now the state doesn't match anymore because the new instance of the app has an empty doc repo.