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

Provide pid in imports callback context #622

Merged
merged 7 commits into from
Sep 2, 2024
Merged

Provide pid in imports callback context #622

merged 7 commits into from
Sep 2, 2024

Conversation

ionull
Copy link
Contributor

@ionull ionull commented Aug 20, 2024

Then we can call exported functions in imported functions.

Then we can call exported functions in imported functions.
@ionull
Copy link
Contributor Author

ionull commented Aug 20, 2024

Sorry, there must be some other way to do this:
** (EXIT) process attempted to call itself

@ionull
Copy link
Contributor Author

ionull commented Aug 20, 2024

When I call the exported function in the imports function callback, there is a timeout exception. Any idea?

@tessi
Copy link
Owner

tessi commented Aug 22, 2024

hey @ionull - I believe I know where the timeout comes from. My suspicion is that this is a rust-side mutex the code it waiting on indefinitely that causes the timeout in elixir-land.

What happens when rust calls into an elixir function is that we have an unlocked mutex on the store_or_caller (the place we all wasm state is stored). That mutex stays locked during the call. Now when you, in elixir-land, call back into rust we need to access that same store_or_caller to mutate the wasm state, trying to unlock that same mutex. But it will never unlock, because we're still running the imported elixir-function.

@ionull
Copy link
Contributor Author

ionull commented Aug 26, 2024

Hi @tessi , the problem is that GenServer has not replied, and the status is locked on the GenServer side, where you can't call with pid, but we still can use the instance to call the wasm exported function like this:
Wasmex.Instance.call_exported_function(store, instance, "__demo_export_0", [a,b],:from)
receive do {:returned_function_call, {:ok, [result]}, :from} -> :ok result after 1000 -> raise "timeout on exported function call" end
It's quite useful if we can get pid and instance from callback context.

@tessi
Copy link
Owner

tessi commented Aug 26, 2024

uhh, interesting. so I was wrong. Nice to learn something :) I get why this is useful. Could you add a test for this scenario, please, so we can make sure not to break it in the future?

@ionull
Copy link
Contributor Author

ionull commented Aug 29, 2024

@tessi Hi, test case done.

@tessi
Copy link
Owner

tessi commented Aug 31, 2024

@tessi Hi, test case done.

perfect! the case looks great to me. thanks a lot. let's see what CI says and merge when/if it's green :)

test/wasmex_test.exs Outdated Show resolved Hide resolved
Co-authored-by: Philipp Tessenow <[email protected]>
@ionull
Copy link
Contributor Author

ionull commented Aug 31, 2024

Is there anything else that I should do?

@tessi
Copy link
Owner

tessi commented Sep 1, 2024

I wanted to say no, but the formatter is still upset. can you make sure mix format --check-formatted works? probably running mix format and a new commit is enough. Other than making formatters happy, I'm happy to merge :)

@ionull
Copy link
Contributor Author

ionull commented Sep 1, 2024

@tessi oh, I see. Have done the mix format, please check

@tessi tessi merged commit aa3c138 into tessi:main Sep 2, 2024
12 checks passed
@tessi
Copy link
Owner

tessi commented Sep 2, 2024

@tessi oh, I see. Have done the mix format, please check

Thanks! And thanks again for your work 💚

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