You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First I've made sure to check that the issue wasn't introduced by wasmtime version changes, the issue is still present
when using versions 3, 4 and 5.
I was unable to find the cause and fix this issue, but I'll present my findings below.
Expected behavior
Lunatic runtime will always create a single process when executing a wasm, this process will inherit all environment
variables from the host machine. Users are allowed to create other processes and control if these processes
will inherit environment variables or provide each process with a custom ProcessConfig which will hold custom
environment variables.
From the example above we expect that the parent process and the first child process
will have the same environment variables, while the second child process will not.
Under the hood
So lets see what exactly happens when the code above is executed and how does Lunatic runtime
manage environment variables.
Each process has its own state (DefaultProcessState), this state holds the WasiCtx.
This context is the "state" to the WASI host function interface and it stores environment variables.
I've check and traced the Lunatic execution and can confirm that passing around the config and environment variables is correct.
That the correct WasiCtx is called from each process.
But in the end the host call fails returning empty array. What is even more strange there is a difference how lunatic::mode::cargo_test and lunatic::mode::execution behave.
In normal execution std::env::vars will correctly return values only for the first process spawned, in all other processes spawned from the first process the std::env::vars call will return an empty array.
In test execution mode std::env::vars always returns an empty array.
Did the unit test ever work?
Also I ran the test suite against the different versions of the runtime.
I'm running this on Linux 5.15.0-58-generic Ubuntu 22.04 with, Rust Version 1.67.0.
What I managed to find out is that the system calls don't even happen. By modifying the original source from wasmtime (wiggle generate_func) I was able to produce this output for the example above. We can see that the parent processes calls three functions in order to execute std::env::vars() while the child process just returns empty array without actual syscalls. But still I can't seem to figure out what is the cause of this behavior.
Issue was first noticed from a failing test config::config_env_variable
First I've made sure to check that the issue wasn't introduced by
wasmtime
version changes, the issue is still presentwhen using versions 3, 4 and 5.
I was unable to find the cause and fix this issue, but I'll present my findings below.
Expected behavior
Lunatic runtime will always create a single process when executing a wasm, this process will inherit all environment
variables from the host machine. Users are allowed to create other processes and control if these processes
will inherit environment variables or provide each process with a custom
ProcessConfig
which will hold customenvironment variables.
e.g. using the Lunatic Rust Library
From the example above we expect that the parent process and the first child process
will have the same environment variables, while the second child process will not.
Under the hood
So lets see what exactly happens when the code above is executed and how does Lunatic runtime
manage environment variables.
Each process has its own state (
DefaultProcessState
), this state holds the WasiCtx.This context is the "state" to the WASI host function interface and it stores environment variables.
lunatic/src/state.rs
Line 64 in 07454fb
WasiCtx and its configuration is either copied from the parent process or is defined manually by creating the
ProcessConfig
.lunatic/crates/lunatic-process-api/src/lib.rs
Line 559 in 07454fb
lunatic/crates/lunatic-process-api/src/lib.rs
Line 581 in 07454fb
lunatic/src/state.rs
Line 141 in 07454fb
Finally when the wasm calls a WASI host function, e.g.
std::env::vars()
, theLinker
makes sure that the correct wasi context is used.lunatic/crates/lunatic-wasi-api/src/lib.rs
Line 52 in 07454fb
I've check and traced the Lunatic execution and can confirm that passing around the config and environment variables is correct.
That the correct WasiCtx is called from each process.
But in the end the host call fails returning empty array. What is even more strange there is a difference how
lunatic::mode::cargo_test
andlunatic::mode::execution
behave.In normal execution
std::env::vars
will correctly return values only for the first process spawned, in all other processes spawned from the first process thestd::env::vars
call will return an empty array.In test execution mode
std::env::vars
always returns an empty array.Did the unit test ever work?
Also I ran the test suite against the different versions of the runtime.
I'm running this on Linux 5.15.0-58-generic Ubuntu 22.04 with, Rust Version 1.67.0.
Does the wasmtime even work
I've written the smallest example of embedded wasmtime runtime and it seems to work.
Source is available here.
Conclusion
What I managed to find out is that the system calls don't even happen. By modifying the original source from wasmtime (wiggle
generate_func
) I was able to produce this output for the example above. We can see that the parent processes calls three functions in order to executestd::env::vars()
while the child process just returns empty array without actual syscalls. But still I can't seem to figure out what is the cause of this behavior.The text was updated successfully, but these errors were encountered: