I am deploying a Rust binary on Windows 10, though the source code should be OS agnostic. When I run a smoke test which invokes the main function of my crate, it fails:
In tests\main.rs
:
use std::process::Command;
use std::process::Stdio;
#[test]
fn my_test() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::main_binary()?;
// Omitted some project specific code
cmd.stderr(Stdio::inherit()).stdout(Stdio::inherit()).unwrap();
}
Note that Command
is from the assert_cmd
library (version 0.10
).
The same goes for running the .exe
file in the target
folder, which, when given the same input as any of my other tests, gives:
C:\path\to\project\target\x86_64-pc-windows-msvc\debug> my_project.ext -i path\to\vetted\output
started
starting memory_intensive_function
thread `main` has overflowed its stack
The main function, however, is not much more than a thin wrapper which parses command line arguments and then internally invokes some functions:
In src\main.rs
pub fn main() -> Result<(), String> {
println!("started")
// parse command line arguments
println!("starting memory_intensive_function");
memory_intensive_function(/* command line arguments here */)?;
println!("completed memory intensive function");
}
The last print statement never prints anything. The weird thing is that I have several tests, 330 in total, of which 40 or so invoke the memory_intensive_function()
directly, and all of these run just fine.
Is there some behavior in Rust that I am not aware of?
I have been toying a bit with the idea of running memory_intensive_function()
on a different blocking thread, but I'm not sure how that would help.
It should be noted that substantially rewriting this function is not really an option (though general tips or guidelines are welcome).
tl;dr A lot of tests which call a memory intensive function works fine, but using this function in main
causes it to crash.