Open mathieulj opened 11 months ago
Having the same code for debug and release does not guarantee identical behavior. The code in question was added because of frequent stack overflows that only happened in debug mode.
Ideally, I would like to avoid the box on release mode.
That said, there are ways to avoid the stack overflow without introducing extra indirection. Those are probably worth exploring.
Close please
I've opened #6826 in an attempt to fix this footgun.
This problem can be relatively tedious to track down for users. To illustrate this with our example:
std::mem::size_of::<T>() > BOX_FUTURE_THRESHOLD
to find all offending futures in our code base. Find & pin them individually. (Not sure if there's a better way, but this worked?)This was a fun riddle, so no complaints at all. :) But I hope this shows that cause and effect can be relatively far apart.
Version
Platform
I've observed this on both macos and windows but the problem likely also affects linux.
Description
In debug builds, spawn will put futures on the heap but the release behaviour is to just pass it on via the stack. This leads to code that passes tests and runs fine in debug but crashes in production if the futures are sufficiently large.
Reproduction steps:
I expected to see this happen: Ideally tokio wouldn't overflow the stack ever but it should at minimum have the same behaviour in debug builds as it does in release builds.
Instead, this happened: tokio overflowed the stack only in release builds, test and debug builds work as expected.