Skip to content

Conversation

@aspect
Copy link

@aspect aspect commented Aug 8, 2024

This addresses kaspanet#516

It appears that holding a Cast to JsValue can result in "out of order" drop that drops JsValue before the cast, causing multiple borrow access to the internal data of the given JsValue (Cast holds a Ref while JsValue::drop() requires borrow_mut(), causing a borrow panic.

I have converted try_cast_from() calls to try_owned_from() which is equivalent to try_cast_from()?.into_owned() making the Cast "transient" in nature (thus dropping the Ref immediately). This appears to have solved the issue.

Not yet sure what the correct approach would be to prevent this. Technically, this should be handled via lifetimes making Cast carry the lifetime of the supplied &JsValue, but not quite sure this is possible, need to experiment to see if the lifetime can be introduced and propagated. An alternative approach would be to have a Cast clone and then own a source JsValue so that the JsValue used to access the ABI cell is isolated and its drop is synchronized with the Cast itself.

…tentially mitigates the JsValue borrow mut issue.
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

Successfully merging this pull request may close these issues.

2 participants