teloxide: thread 'main' has overflowed its stack
I tried this code: https://github.com/teloxide/teloxide/blob/master/crates/teloxide/examples/purchase.rs I expected to see this happen: https://github.com/teloxide/teloxide/blob/7b2de9ad39f3a0841f9058d21389805e4880724a/crates/teloxide/examples/purchase.rs#L11C1-L12C65
Instead, this happened:
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.30s
Running `target\debug\untitled.exe untitled`
thread 'main' has overflowed its stack
error: process didn't exit successfully: `target\debug\untitled.exe untitled` (exit code: 0xc00000fd, STATUS_STACK_OVERFLOW)
Meta
teloxideversion: 0.13.0
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 35 (6 by maintainers)
After some time, pain of windows development and lack of success i gathered that much:
Messagedeserialization, which then pointed to thisdeserialize_mapfunction (and then debuggers just gave plain assembly)Possible solutions:
1. Add
to
Cargo.toml, it lowers the needed stack size to just 400Kb, but it increases the testing compilation time x2 (users won’t notice, they need to compile teloxide only once, but development will get slower). It is a solution that will fix all future stack problems, and a lot of projects do use it2. Find some rust flag that doesn’t increase the compile time too much, but reduces the stack usage
(if someone knows it - please tell, i couldn’t find it at all)
3. Increase the stack size to 4Mb or 8Mb inside of teloxide (if even possible), maybe make windows-specific or debug only.
This solution has no large downsides, but I don’t know if it is good to force the stack size to be bigger by default, especially if someone wants to increase the stack size even more by themselves for their specific application
4. Find a way to optimize stack usage in teloxide?..
Not sure if possible
5. Try to find out why deserialization into
Messageitself causes so much troubleBecause deserializing into value like this in the update
Messagedeserialization:Works fine, but if i add
It causes an overflow
@syrtcevvi and @Hirrolot, what do you think? I’m completely lost on this, and this issue seems extremely important for windows devs, it is extremely easy to come across (just lauching (!!!) even the
throw_dice(!!!) example exactly like said in the README does the trick, which is not good), and i think this needs to be addressed ASAP in the next releaseIf something needs to be tested - tell me, i’ll launch it on my machine
There are 2 problems, both of them are in serde One for incoming
Messageupdate deserialization (the original issue), and another is… Im not sure if its serialization or deserialization, but it’s also serde (because without derivingSerializeandDeserializeonStatethe trait bounds are not satisfied) I think its the same basic type of error, and finding a way to fix this more recreatable issue will probably give a way to fix the original issueWell, we can’t expect users to do that just to launch
cargo runon their botsWhat is the best solution here in your opinion?
Actually, it has nothing to do with
teloxide, but actually withtokioruntime, iirc. It’s possible to create the runtime with increased stack-size for worker-threads (you need to get rid of #[tokio::main] macro and create an instance of the runtime by yourself)https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html#method.thread_stack_size
P.s.
--releaseflag turns on all possible compiler optimizations, it increases the compile time and the performance of the resulting programP.s.s memory leaks in rust still possible due to the use of the
old stuff, allocators, libs (c libs) (for instance, axum issues (or issued?) a memory leak)