fix tokio runtime stack overflow due to recursion
This commit is contained in:
parent
7adf770d54
commit
c163860c0a
2 changed files with 18 additions and 1 deletions
|
@ -1,12 +1,18 @@
|
||||||
use std::{ffi::OsStr, process::Command};
|
use std::{ffi::OsStr, process::Command};
|
||||||
|
|
||||||
|
|
||||||
|
use parking_lot::Mutex;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
|
|
||||||
use crate::core::repl::repl::evaluate_command;
|
use crate::core::repl::repl::evaluate_command;
|
||||||
|
|
||||||
use super::COMMAND_LIST;
|
use super::COMMAND_LIST;
|
||||||
|
const MAX_RECURSION_DEPTH: usize = 500; // increasing this value WILL cause a stack overflow. attempt at your own risk - Caz
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref RECURSION_DEPTH: Mutex<usize> = parking_lot::Mutex::new(0);
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn say_hello() -> anyhow::Result<()> {
|
pub(crate) fn say_hello() -> anyhow::Result<()> {
|
||||||
println!("Hello, World!");
|
println!("Hello, World!");
|
||||||
|
@ -41,6 +47,13 @@ pub(crate) fn help() -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub(crate) fn exec(args: Vec<String>) -> anyhow::Result<()> {
|
pub(crate) fn exec(args: Vec<String>) -> anyhow::Result<()> {
|
||||||
|
*RECURSION_DEPTH.lock() += 1;
|
||||||
|
if *RECURSION_DEPTH.lock() > MAX_RECURSION_DEPTH {
|
||||||
|
eprintln!("Maximum recursion depth reached. Aborting.");
|
||||||
|
*RECURSION_DEPTH.lock() = 0;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
println!("Recursion depth: {}", *RECURSION_DEPTH.lock());
|
||||||
let file_path_str = &args[0];
|
let file_path_str = &args[0];
|
||||||
let file_path = std::path::Path::new(file_path_str);
|
let file_path = std::path::Path::new(file_path_str);
|
||||||
println!("File path: {:#?}", file_path);
|
println!("File path: {:#?}", file_path);
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
echo ping
|
||||||
|
echo pong
|
||||||
|
exec test.zensh
|
||||||
|
break
|
Loading…
Add table
Add a link
Reference in a new issue