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

Bug: recursive use of an object detected which would lead to unsafe aliasing in rust #87

Open
2 tasks done
orimay opened this issue Jun 22, 2024 · 8 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@orimay
Copy link
Contributor

orimay commented Jun 22, 2024

Describe the bug

I keep getting the same error, can't track the root of where it's coming from.

patched.js:1121 
 Uncaught 
Error: recursive use of an object detected which would lead to unsafe aliasing in rust
    at __wbindgen_throw (patched.js:1121:19)
    at 036c96f6:0xbb3af6
    at 036c96f6:0xbb3b05
    at 036c96f6:0xa8912e
    at 036c96f6:0x4c57dc
    at 036c96f6:0x7d5013
    at 036c96f6:0xab61d3
    at __wbg_adapter_58 (patched.js:264:10)
    at real (patched.js:231:20)
__wbindgen_throw	@	patched.js:1121
$func17604	@	036c96f6:0xbb3af6
$func17605	@	036c96f6:0xbb3b05
$func12906	@	036c96f6:0xa8912e
$func782	@	036c96f6:0x4c57dc
$func3470	@	036c96f6:0x7d5013
$__wbindgen_export_5	@	036c96f6:0xab61d3
__wbg_adapter_58	@	patched.js:264
real	@	patched.js:231
IndexedDB (async)		
(anonymous)	@	patched.js:751
handleError	@	patched.js:269
__wbg_get_5361b64cac0d0826	@	patched.js:750
$func8944	@	036c96f6:0xa1c086
$func1879	@	036c96f6:0x68527a
$func2734	@	036c96f6:0x7256e9
$func4368	@	036c96f6:0x8a7f36
$func1194	@	036c96f6:0x58df33
$func15310	@	036c96f6:0xac05be
$func169	@	036c96f6:0x1c8bc9
$func144	@	036c96f6:0x8ed9c
$func172	@	036c96f6:0x1d343b
$func2943	@	036c96f6:0x73e7ef
$func1642	@	036c96f6:0x61884f
$func854	@	036c96f6:0x4f7e35
$func782	@	036c96f6:0x4d3466
$func3470	@	036c96f6:0x7d5013
$__wbindgen_export_5	@	036c96f6:0xab61d3
__wbg_adapter_58	@	patched.js:264
real	@	patched.js:231

Steps to reproduce

Not sure if this is enough (the project is big), but here's my setup:

import { Emitter, Engine, Surreal, type EngineEvents } from 'surrealdb.js';
import { surrealdbWasmEngines } from 'surrealdb.wasm';

const db = new Surreal({
  engines: surrealdbWasmEngines({
    strict: false,
    capabilities: {
      guest_access: true,
      functions: true,
      network_targets: true,
    },
  }) as Record<string, new (emitter: Emitter<EngineEvents>) => Engine>, // this is not properly typed in surrealdb.wasm
});

Expected behaviour

Should not error out

SurrealDB version

surrealdb.js: 1.0.0-beta.9, surrealdb.wasm: 1.0.0-beta.12

Contact Details

[email protected]

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@orimay orimay added the bug Something isn't working label Jun 22, 2024
@orimay
Copy link
Contributor Author

orimay commented Jun 26, 2024

It turns out, it is related to this issue: https://stackoverflow.com/questions/61296252/failed-to-execute-put-on-idbobjectstore-the-transaction-has-finished

IndexDB doesn't really like multiple asynchronous requests. Once I wrapped query in mutex, it worked:

import { Mutex } from 'mutex-ts';

const mutex = new Mutex();

const query = db.query;
db.query = async <T extends unknown[]>(
  ...args: [string | PreparedQuery, Record<string, unknown> | undefined]
) => {
  const release = await mutex.obtain();
  try {
    return await (query.apply(db, args) as Promise<T>);
  } finally {
    release();
  }
};

mutex-ts is my library.

@orimay
Copy link
Contributor Author

orimay commented Jul 20, 2024

I am also still getting it sometimes, but not sure how to fix it on my end

@limcheekin
Copy link

Facing the same issue here on surrealdb.js: 1.0.0-beta.14, surrealdb.wasm: 1.0.0-beta.14.

@limcheekin
Copy link

Just re-test in surrealdb.js: 1.0.0-beta.20 and surrealdb.wasm: 1.0.0-beta.16, it is blocking issue holding back surrealdb.wasm to be used in any web application.

@orimay
Copy link
Contributor Author

orimay commented Aug 21, 2024

@limcheekin, you may try using my approach above for the time being

@limcheekin
Copy link

@orimay Thanks, I am aware about your approach, but I am using surrealdb.wasm in a Flutter Web application.

@ibilux
Copy link

ibilux commented Aug 23, 2024

+1

@limcheekin
Copy link

I tested the latest release of the surrealdb.wasm 1.0.1 for few days, it seems the issue had been resolved by the PR.

@orimay do you have time to test it out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants