-
Notifications
You must be signed in to change notification settings - Fork 51
Improved Test Coverage. #192
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
Improved Test Coverage. #192
Conversation
Fixed one small issue in the process: - Modified `wasmtime_engine_increment_epoch` to return `void` instead of `IntPtr`. Based on signature from these docs: https://docs.wasmtime.dev/c-api/engine_8h.html
CI failure is due to a 404 on |
Note that it does actually print an error description to
I'm not quite sure (I don't know Rust), but this behavior (directly printing error information to Additionally, if you catch that
|
@kpreisser you're correct that a Rust panic in this case is meant to terminate the process. I don't think we need to guard against configuration validation errors in the .NET version of To fix that properly, I suggest filing an upstream issue in wasmtime to add a fallible version of That way we can surface the error as a proper exception on the .NET side and not have to duplicate configuration validation logic in the .NET bindings. |
@martindevans thanks for improving the test coverage! |
Hi @peterhuene ,
do we need to do something about this? Currently, on Windows, when a Rust panic occurs in Wasmtime that is actually meant to terminate the process (due to an unrecoverable error as I understand it), .NET code can still catch it e.g. with a However, I'm not sure that would be the best way to fix this. A naive way to handle this in .NET code in public static unsafe IntPtr wasmtime_func_call(IntPtr context, in ExternFunc func, Value* args, nuint nargs, Value* results, nuint nresults, out IntPtr trap)
{
try
{
return LocalFunc(context, func, args, nargs, results, nresults, out trap);
}
catch (SEHException ex)
{
// This is likely a Rust panic, so terminate the process.
Environment.FailFast(ex.Message, ex);
// Satisfy CFA, this line is not reached.
throw;
}
[DllImport(Engine.LibraryName)]
static unsafe extern IntPtr LocalFunc(IntPtr context, in ExternFunc func, Value* args, nuint nargs, Value* results, nuint nresults, out IntPtr trap);
} (or using an exception filter with a However, this would theoretically be needed for every native function, and might make the code ugly. (This could be done instead with a Source Generator similar to the one for the Though, maybe this can or should also be fixed directly in Wasmtime or Rust. I saw that with PRs rust-lang/rust#26569 and rust-lang/rust#32900, Rust by default seems to use SEH's Alternatively there is Do you know why Wasmtime/Rust currently don't use a mode that will abort the process for a panic on Windows? |
I consider catching (and potentially eating) That said, I do think changing the panic mode for the C API to abort would make the most sense to address this issue. Would you mind opening an issue in the Wasmtime repo to explore doing so and reference this conversation? Additionally, I would like to see is less |
Thanks for your reply!
Note that sometimes you may have to wasmtime-dotnet/src/Function.cs Lines 1959 to 1962 in 972ef24
Imagine there are host-to-wasm and wasm-to-host transitions on the stack, and you call a Wasmtime function that panics, resulting in a (Also, note that .NET has a concept of "corrupted state exceptions" that cannot be caught with a
Agreed, that would certainly be a better option than trying to work-around this in
👍 (my comment was mostly generally about possible Rust panics in wasmtime, not specifically to the panic caused by a wrong config option). Thank you! |
Added some more tests and fixed one small issue in the process:
wasmtime_engine_increment_epoch
to returnvoid
instead ofIntPtr
. Based on signature from these docs: https://docs.wasmtime.dev/c-api/engine_8h.htmlProposal
While writing the tests for the config I also came across an awkward error to do with disabling bulk memory. As documented here if
Bulk memory = false
then it is required thatReference Type = false
. If that is not the case then creating the engine throws this exception:System.Runtime.InteropServices.SEHException: 'External component has thrown an exception.'
, with absolutely no indication of what is wrong.I would like to modify
WithBulkMemory
to look like this:i.e. disabling bulk memory automatically disables reference types.