Skip to content

Commit

Permalink
fix tokio runtime stack overflow due to recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
Caznix committed Dec 6, 2024
1 parent 48bdd14 commit 4d2383d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 14 additions & 1 deletion engine/src/core/repl/commands.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
use std::{ffi::OsStr, process::Command};



use parking_lot::Mutex;
use lazy_static::lazy_static;


use crate::core::repl::repl::evaluate_command;

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<()> {
println!("Hello, World!");
Expand Down Expand Up @@ -41,6 +47,13 @@ pub(crate) fn help() -> anyhow::Result<()> {
Ok(())
}
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 = std::path::Path::new(file_path_str);
println!("File path: {:#?}", file_path);
Expand Down
4 changes: 4 additions & 0 deletions test.zensh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
echo ping
echo pong
exec test.zensh
break

0 comments on commit 4d2383d

Please sign in to comment.