Skip to content
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

bug: thread '<unknown>' has overflowed its stack #185

Closed
junhwong opened this issue Jun 5, 2017 · 21 comments
Closed

bug: thread '<unknown>' has overflowed its stack #185

junhwong opened this issue Jun 5, 2017 · 21 comments

Comments

@junhwong
Copy link

junhwong commented Jun 5, 2017

Hi, i use tera with Rocket, run and crash of thread '' has overflowed its stack.
pls see: rwf2/Rocket#309

@Keats
Copy link
Owner

Keats commented Jun 6, 2017

Can you fork Tera master, add the failing template as a test case and see if it works? 0.7.2 is 3 versions behind so we need to see if it still happens in the current version and whether it's a Tera bug

@junhwong
Copy link
Author

junhwong commented Jun 6, 2017

@Keats I have tried, can determine the compile_templates! problem. But it does not have any wrong details.
The following is the test code for the test case:

    use tera::Tera;
    let mut ctx = tera::Context::new();
    //panic!("never returns!");
    let tera = compile_templates!("templates/test/*");
    tera.render("index.html.tera", &ctx);

@Keats
Copy link
Owner

Keats commented Jun 6, 2017

What about the templates? Can you push a sample project that fails on github or gitlab?

@junhwong
Copy link
Author

junhwong commented Jun 6, 2017

this template:

{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}{{order_id}}

@Keats
Copy link
Owner

Keats commented Jun 7, 2017

I've added a test with a template twice bigger than this one and I don't get the error: #186

Can you checkout this branch and create a failing test case?

@junhwong
Copy link
Author

junhwong commented Jun 7, 2017

@Keats Use cargo test is passed, but use cargo run is failed!

see test projects https://github.com/junhwong/tera_test

@Keats
Copy link
Owner

Keats commented Jun 7, 2017

Hmm both cargo test and cargo run work for me on your repo.
What error do you get? Still thread '<unknown>' has overflowed its stack?

@Eijebong
Copy link
Contributor

Eijebong commented Jun 7, 2017

@junhwong Are you using windows ?

I know clippy had troubles with 64 bit windows stack being too short. https://github.com/Manishearth/rust-clippy/issues/1244 might be the same kind of issue here ?

@junhwong
Copy link
Author

junhwong commented Jun 7, 2017

@Eijebong @Keats
Yes i use win 10 pro. but i set RUST_MIN_STACK is invalid and still thread '<unknown>' has overflowed its stack error.

try:

fn main() {
    use std::env;
    use std::thread;
    use tera::Tera;
    let child = thread::Builder::new().stack_size(2 * 1024 * 1024).spawn(move || {
        let mut ctx = tera::Context::new();
        let tera = compile_templates!("templates/*");
        tera.render("index.html", &ctx);
        println!("PASSED");
    }).unwrap();
    println!("min_stack:{:?}", env::var("RUST_MIN_STACK"));
    println!("max_cached_stacks:{:?}", env::var("RUST_CACHED_STACKS"));
    child.join().unwrap();
}

is passed, stack_size 2M is enough,results:

Finished dev [unoptimized + debuginfo] target(s) in 2.14 secs
     Running `target\debug\tera_test.exe`
min_stack:Ok("33554432")
max_cached_stacks:Err(NotPresent)
PASSED

so i still can not sure the root of the problem.
and i submit this test code to test projects https://github.com/junhwong/tera_test

@Keats
Copy link
Owner

Keats commented Jun 8, 2017

What's your rust version? Can you post the full stacktrace of the error?

@junhwong
Copy link
Author

junhwong commented Jun 8, 2017

@Keats rust version is last version and error only thread '<unknown>' has overflowed its stack
see rwf2/Rocket#309 for get stacktrace tries.

@Keats
Copy link
Owner

Keats commented Jun 8, 2017

The backtrace seems to be about your panic! call: thread 'main' panicked at 'This function never returns!', src\main.rs:115
What's the backtrace if you just run https://github.com/junhwong/tera_test/blob/master/src/main.rs#L22-L27?

@junhwong
Copy link
Author

junhwong commented Jun 8, 2017

panic! is used to test stacktrace only . results is here:rwf2/Rocket#309 (comment)

@junhwong
Copy link
Author

junhwong commented Jun 8, 2017

If really can not find the reason, then i use test repo ways for hack to complete my works!
Well, that's only that, THX!

@Keats
Copy link
Owner

Keats commented Jun 8, 2017

Maybe open a thread on https://reddit.com/r/rust or http://users.rust-lang.org/, I have no idea what's going on myself

@Keats
Copy link
Owner

Keats commented Jun 11, 2017

Did you manage to figure it out? If not I'd like to post it on http://users.rust-lang.org/ since I'd like to have it fixed for everyone

@Keats
Copy link
Owner

Keats commented Jun 13, 2017

That's weird, it seems I can reproduce it now on my machine

@junhwong
Copy link
Author

@Keats Yes this is a strange question, i just hack it now and i also look forward to the solution to this problem.

@Keats
Copy link
Owner

Keats commented Jun 14, 2017

I believe this is the same issue as https://stackoverflow.com/questions/28660362/thread-main-has-overflowed-its-stack-when-constructing-a-large-tree as I use VecDeque when building the AST.
I tried implementing Drop for Node but it overflows before reaching it, removing most of the VecDeque and just using Vec but the issue is still there.

(branch with failing test and some changes like using Vec instead of VecDeque in some places: https://github.com/Keats/tera/tree/overflow, cargo run --example basic to get the error)

@Keats
Copy link
Owner

Keats commented Jun 16, 2017

This is apparently due to a bug in the parser lib Tera is using. This lib has a 1.0 coming soon that is almost a full rewrite and that should not present this issue. So in theory this should be fixed in the next 0.11 version after pest reaches 1.0

@Keats Keats mentioned this issue Jul 31, 2017
8 tasks
@Keats
Copy link
Owner

Keats commented Nov 24, 2017

Fixed as of 0.11.0-beta, sorry for the delay :o

@Keats Keats closed this as completed Nov 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants