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

Kotlin bindings error: java.lang.AssertionError: Handle map is not returning the object we just placed there. This is a bug in the HandleMap. #1610

Open
krisbitney opened this issue Jun 19, 2023 · 5 comments
Labels

Comments

@krisbitney
Copy link

krisbitney commented Jun 19, 2023

Hi,

UPDATE: I now think the problem is a race condition. More details are provided in the comments below.

I am getting the following exception thrown in Kotlin uniffi bindings. Could anyone suggest some possible causes of this?

``java.lang.AssertionError: Handle map is not returning the object we just placed there. This is a bug in the HandleMap.``

The full error is here, though a lot of the context is not uniffi-related.
image

┆Issue is synchronized with this Jira Task
┆Issue Number: UNIFFI-290

@badboy
Copy link
Member

badboy commented Jun 20, 2023

Can you show your code?

@krisbitney
Copy link
Author

krisbitney commented Jun 20, 2023

Can you show your code?

Here is the Kotlin repo: https://github.com/polywrap/kotlin-client/tree/kris/uniffi-rework
Here are the Kotlin plugins: https://github.com/polywrap/kotlin-client/tree/main/src/commonMain/kotlin/io/polywrap/plugins
Here is the FFI package: https://github.com/polywrap/rust-client/tree/main/packages/native
Here is the rust repo the FFI is layered on top of: https://github.com/polywrap/rust-client/tree/main

The error occurs when calling createWrapper here: https://github.com/polywrap/rust-client/blob/main/packages/client/src/client.rs#L200

The Rust WrapPackage that panics is a wrapper around a callback interface. The createWrapper method is called in the Kotlin WrapPackage that implements the interface here: https://github.com/polywrap/kotlin-client/blob/kris/uniffi-rework/src/commonMain/kotlin/io/polywrap/plugin/PluginPackage.kt#L31

There is no problem calling createWrapper on our FileSystemPlugin, but there is an issue with the HttpPlugin.

@krisbitney
Copy link
Author

UPDATE

Here is a maximally simple reproduction of the error: polywrap/kotlin-client#40

The issue occurs when a call is made from a Wasm module, to Rust native code, which then calls Kotlin code through UniFFI bindings.

@krisbitney
Copy link
Author

krisbitney commented Jul 27, 2023

Note that in the original case the error was occurring the SECOND time the call to the Kotlin object was made:

Kotlin base
Rust native
Wasm module
Rust native
Wasm module
Kotlin plugin (success)
Return from Kotlin
Return from Wasm
Return from Rust
Return from Wasm
Rust native
Wasm module
Rust native
Wasm module
Kotlin plugin (fail -> handlemap error)

@krisbitney
Copy link
Author

krisbitney commented Jul 27, 2023

Some logs for you, from printlns I added to the generated handlemap. These logs come from after I fixed the bug on our end.

The original issue was that the kotlin object inserted into the handlemap was a new instance of the object that was already there. It seems like a race condition.

Now my code works, but uniffi prints a lot of errors (which don't seem to affect whether my code actually functions). The new exceptions are caused by attempts to get the kotlin object from the handlemap that is dropped at the end of this log.

It's important to know that our Rust code is completely synchronous.

Inserted PluginPackage(pluginModule=MemoryStoragePlugin@4f4c4b1a, manifest=WrapManifest01(version=0.1.0, type=plugin, name=mockManifest, abi=Abi01(version=0.1, objectTypes=null, moduleType=null, enumTypes=null, interfaceTypes=null, importedObjectTypes=null, importedModuleTypes=null, importedEnumTypes=null, importedEnvTypes=null, envType=null))) into handle map at 0
Inserted PluginPackage(pluginModule=MemoryStoragePlugin@6c61a903, manifest=WrapManifest01(version=0.1.0, type=plugin, name=mockManifest, abi=Abi01(version=0.1, objectTypes=null, moduleType=null, enumTypes=null, interfaceTypes=null, importedObjectTypes=null, importedModuleTypes=null, importedEnumTypes=null, importedEnvTypes=null, envType=null))) into handle map at 1
Inserted PluginPackage(pluginModule=MemoryStoragePlugin@658c5a19, manifest=WrapManifest01(version=0.1.0, type=plugin, name=mockManifest, abi=Abi01(version=0.1, objectTypes=null, moduleType=null, enumTypes=null, interfaceTypes=null, importedObjectTypes=null, importedModuleTypes=null, importedEnumTypes=null, importedEnvTypes=null, envType=null))) into handle map at 2
Inserted PluginPackage(pluginModule=MemoryStoragePlugin@421e361, manifest=WrapManifest01(version=0.1.0, type=plugin, name=mockManifest, abi=Abi01(version=0.1, objectTypes=null, moduleType=null, enumTypes=null, interfaceTypes=null, importedObjectTypes=null, importedModuleTypes=null, importedEnumTypes=null, importedEnvTypes=null, envType=null))) into handle map at 3
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Inserted PluginWrapper(module=MemoryStoragePlugin@421e361) into handle map at 0
Dropping handle 0
Inserted PluginPackage(pluginModule=MemoryStoragePlugin@3c435123, manifest=WrapManifest01(version=0.1.0, type=plugin, name=mockManifest, abi=Abi01(version=0.1, objectTypes=null, moduleType=null, enumTypes=null, interfaceTypes=null, importedObjectTypes=null, importedModuleTypes=null, importedEnumTypes=null, importedEnvTypes=null, envType=null))) into handle map at 4
Inserted PluginPackage(pluginModule=MemoryStoragePlugin@50fe837a, manifest=WrapManifest01(version=0.1.0, type=plugin, name=mockManifest, abi=Abi01(version=0.1, objectTypes=null, moduleType=null, enumTypes=null, interfaceTypes=null, importedObjectTypes=null, importedModuleTypes=null, importedEnumTypes=null, importedEnvTypes=null, envType=null))) into handle map at 5

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

No branches or pull requests

3 participants