-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Maximum call stack size exceeded during encryptString #5624
Comments
this only happens when using wrappedKeyEncryptionWebCryptoStorage in the worker instead of the main thread |
Could reproduce but atm I have no idea what is going on here. export function ab2b64(arrayBuffer: ArrayBuffer): string {
return b64EncodeUnicode(String.fromCharCode.apply(null, new Uint8Array(arrayBuffer) as any));
}
import { encode, decode } from 'js-base64';
/**
* atob() and btoa() do not work well with non ascii chars,
* so we have to use these helper methods instead.
* @link https://stackoverflow.com/a/30106551/3443137
*/
// Encoding UTF8 -> base64
export function b64EncodeUnicode(str: string) {
return encode(str);
} |
I think this error only occurs inside of the worker, because web workers have a small max stack size. Using Also calling js-base64 encode directly causes the same error: import { encode } from 'js-base64';
const strangeText = okText.repeat(8);
encode(strangeText); I was not sure if I can share your demo-code string so please create an issue or make a PR at the js-base64 repo. |
hm it's weird I also tried repeat(1000) https://stackblitz.com/edit/vitejs-vite-brcepd?file=src%2Fmain.ts |
This is so strange. Running your example also works for me. I also added base64-js via cdn to a plain html file and run the code which worked. Only in my karma-browserify test setup it fails (newest chrome). |
Probably the error is not in my specific string and its repetition, but in the length of the document. function generateRandomString(length) { const randomText = generateRandomString(1000 * 125); // ok in main thread ×126 will cause an error in shared worker it's ×63 max |
maybe you have to split |
I could not reliably reproduce that with the plain base64-js encode function. Can you make a stackbliz with that? I tried this but this does not show the error: https://stackblitz.com/edit/vitejs-vite-ggmddh?file=src%2Fmain.ts |
yes, because the problem is with Uint8Array not base64-js I updated this example https://stackblitz.com/edit/vitejs-vite-kgrb6y?file=src%2Fmain.ts see the line 56 if you make randomText longer (more than 125), it will fail |
But where is ab2b64WithoutEncode from? Because it is neither used in rxdb nor in js-base64. |
its your function without b64EncodeUnicode (updated by me) |
@ahoyahoy Can you try the latest release? This should be fixed now, I added your proposed chunking to prevent the error. |
it works, thanks :) |
minimal example https://github.com/ahoyahoy/rxdb-shared-worker-error/blob/crypto/src/main.ts#L41C7-L41C19
crypto
branchThere is a "long" string
okText
.I found one document that caused me a problem during data replication.
I gradually deleted all the props from it until there were only a few left (similar) and they together caused a problem, if I deleted one of them, no problem.
But I found that even if I take just one of them and repeat it a few times, I get the same problem. see
strangeText
With this string I'm getting this error
helpers.js:1 Uncaught (in promise) RangeError: Maximum call stack size exceeded
at ab2b64 (helpers.js:1:1187)
at encryptString (helpers.js:1:1376)
I also tried to make much longer random string and no problem.
"rxdb": "15.7.0",
"rxdb-premium": "15.7.0",
The text was updated successfully, but these errors were encountered: