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

IndexedDB closure invoked recursively or after being dropped issue #2019

Closed
laruh opened this issue Dec 5, 2023 · 3 comments
Closed

IndexedDB closure invoked recursively or after being dropped issue #2019

laruh opened this issue Dec 5, 2023 · 3 comments
Assignees

Comments

@laruh
Copy link
Member

laruh commented Dec 5, 2023

Uncaught Error: closure invoked recursively or after being dropped

This runtime wasm error appears, when in storage implementations for wasm target we build cursor, open it, and iterate items in while loop, using next method of CursorIter

Could be connected to this

@laruh
Copy link
Member Author

laruh commented Dec 6, 2023

Some useful info:

Seems like the problem is that _onsuccess_closure and _onerror_closure closures are invoked after the CursorDriver has been dropped.

Screenshot from 2023-12-05 21-09-53

The thing is that CursorIter::collect() method uses next, but collect function usage after opening cursor doesnt have runtime errors, while items iteration with next has them.

Also here are functions which are needed to take into account:

@borngraced
Copy link
Member

borngraced commented Dec 9, 2023

this bug exist while calling next once like this(explained properly in my pr)

let maybe_height = block_db
.cursor_builder()
.only("ticker", &ticker)?
.bound("height", 0u32, u32::MAX)
.reverse()
.open_cursor(BlockDbTable::TICKER_HEIGHT_INDEX)
.await?
.next()
.await?;

I have a fix here..that might close this issue too. can you test on your branch @laruh

@laruh
Copy link
Member Author

laruh commented Dec 10, 2023

@borngraced yeah, seems like the problem occurs when we try to get only first item with next() method. This fix solves runtime error :) Good job!

As you mentioned in PR description

return only the first result we care for and stop CursorDriver next loop immediately and Drop

I see that the problem was here

match cursor_action {
CursorAction::Continue => cursor.continue_().map_to_mm(|e| CursorError::AdvanceError {

In the CursorDriver's next loop, the cursor_action was CursorAction::Continue type. However, due to the absence of the !first_row_only check, the continue_ method from web_sys was called, which attempted to invoke closures after CursorDriver being dropped.
In the get first item case CursorAction::Continue => cursor.continue_() wont be called, so no next items.

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

3 participants