Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out of memory errors after creating enough large documents in repo #330

Open
georgewsu opened this issue Mar 30, 2024 · 7 comments
Open

Comments

@georgewsu
Copy link
Contributor

georgewsu commented Mar 30, 2024

Hi, running in to this error when testing an automerge client with a 10MB test document.

Node.js v18.15.0

Steps to reproduce:

Start the sync server

git clone https://github.com/automerge/automerge-repo-sync-server.git
cd automerge-repo-sync-server
npm install
npm start

Then run the client
https://github.com/georgewsu/automerge-client-test/tree/error_recursive_use

git clone https://github.com/georgewsu/automerge-client-test.git
cd automerge-client-test
git checkout error_recursive_use
npm install
npm run client

code excerpt:
https://github.com/georgewsu/automerge-client-test/blob/error_recursive_use/src/client.ts

const stringArray: string[] = new Array(arrayLength).fill(stringWith100Characters);
const testJson = {
  stringArray: stringArray
};
const testDoc = A.from(testJson);
const handle1 = repo1.create(testDoc);

Result:

Error: recursive use of an object detected which would lead to unsafe aliasing in rust
    at module.exports.__wbindgen_throw (/Users/gsu/repo2/automerge-client-test/node_modules/@automerge/automerge-wasm/nodejs/automerge_wasm.cjs:1990:11)
    at wasm_bindgen::throw_str::hc0015d8a92fcec96 (wasm://wasm/00664e02:wasm-function[2065]:0x157683)
    at wasm_bindgen::__rt::borrow_fail::hd13a3345a14a3b49 (wasm://wasm/00664e02:wasm-function[2067]:0x15769f)
    at automerge_rollback (wasm://wasm/00664e02:wasm-function[1668]:0x1545ce)
    at Automerge.rollback (/Users/gsu/repo2/automerge-client-test/node_modules/@automerge/automerge-wasm/nodejs/automerge_wasm.cjs:544:26)
    at _change (file:///Users/gsu/repo2/automerge-client-test/node_modules/@automerge/automerge/dist/mjs/stable.js:378:22)
    at Module.from (file:///Users/gsu/repo2/automerge-client-test/node_modules/@automerge/automerge/dist/mjs/stable.js:176:12)
    at Module.from (file:///Users/gsu/repo2/automerge-client-test/node_modules/@automerge/automerge/dist/mjs/next.js:98:19)
    at new DocHandle (file:///Users/gsu/repo2/automerge-client-test/node_modules/@automerge/automerge-repo/dist/DocHandle.js:51:21)
    at #getHandle (file:///Users/gsu/repo2/automerge-client-test/node_modules/@automerge/automerge-repo/dist/Repo.js:244:24)

@georgewsu
Copy link
Contributor Author

Alternative steps to reproduce:

https://github.com/georgewsu/automerge-client-test/tree/file_error

git checkout file_error
gunzip generated.json.gz
mkdir -p dist
cp generated.json dist/data.json
npm install
npm run client

This branch creates a doc from json file contents. The generated json file was created using https://json-generator.com/ with repeat 10000, 10000.

@acurrieclark
Copy link
Collaborator

I haven’t had a chance to verify this myself, but it looks as though you are passing an automerge document in to Repo.create().

create should be used without parameters to create an empty doc handle, or with an object to initialise the document handle structure.

Essentially, you might have better luck if you skip the from call and pass testJson directly in to create.

@georgewsu
Copy link
Contributor Author

I haven’t had a chance to verify this myself, but it looks as though you are passing an automerge document in to Repo.create().

create should be used without parameters to create an empty doc handle, or with an object to initialise the document handle structure.

Essentially, you might have better luck if you skip the from call and pass testJson directly in to create.

Hi, unfortunately that still doesn't prevent the error from happening. It does save a step and reduce the time it takes at least. Thanks

@georgewsu
Copy link
Contributor Author

georgewsu commented Apr 3, 2024

To clarify, it takes multiple documents to trigger the error on the server:

cd automerge-client-test
git checkout file_error
du -sh dist/data.json ; echo "should be several MB"
for i in {1..10}; do npm run client; done

@georgewsu
Copy link
Contributor Author

fyi, the error message "recursive use of an object detected which would lead to unsafe aliasing in rust" is being thrown from the call to rollback and obscuring the actual underlying error

you can test it out by wrapping the call to state.handle.rollback() in a try/catch block

@georgewsu georgewsu changed the title Error: recursive use of an object detected which would lead to unsafe aliasing in rust Out of memory errors after creating enough large documents in repo Jul 29, 2024
@georgewsu
Copy link
Contributor Author

Changed issue title from "Error: recursive use of an object detected which would lead to unsafe aliasing in rust" to "Out of memory errors after creating enough large documents in repo"

@georgewsu
Copy link
Contributor Author

Same issue as #358

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants