Hi,
I've been having some troubles with a StackOverflowDetectedException. I'm afraid I currently don't have a clear reproduction case, as I'm not sure why this is occurring. And the code I'm working on is proprietary, so I wouldn't be able to share it directly.
On the off chance that maybe someone has an intuitive sense of what the problem might be, though, here's what I know:
One of my tests is failing due to a StackOverflowDetectedException.
Notably, however, it passes when I run it using the Visual Studio test runner (I'm using xUnit) and when I run it using dotnet test from a command line.
In neither case do I run into an actual stack overflow.
There are threads and socket calls involved, so this is far from a unit test (it's part of an acceptance test suite), but I would like to be able to run it through NCrunch to make potential debugging easier.
Looking at a snapshot of managed memory in Visual Studio at the time of the StackOverflowDetectedException, I notice no immediate red flags.
Most memory is taken by nCrunch.TestRuntime.TestExecutionMap at 3.384.128B and nCrunch.Common.IO.FilePath at 74.052B, but both of these seem to be of similar size when running other tests that do not have this issue.
I haven't found the usual culprit of recursion anywhere either.
One final note, I tried setting the "Detect stack overflow" option in the module configuration to False.
I had hoped that I might run into some different error/crash to lead me to the underlying problem, but the same StackOverflowDetectedException was thrown.
Does anyone have some insight into what might be going on?
Build/Test Issues
StackOverflowDetectedException in NCrunch, but test passes in other runners
Started by TobiasvdVen on 1,967 views
Remco NCrunch Developer
#16222
30 Jul 2022 00:16 UTC
Hi, thanks for sharing this problem.
NCrunch intercepts stack overflows by tracking the size of the overall stack and throwing an exception when it reaches a certain threshold. This process is not as perfect as I'd like it to be, owing that the acceptable stack size seems to be extremely variable depending on the context and we end up trying to guess at when it is highly likely to occur.
My first guess is that you have code that is running up the stack significantly, but it is probably normal behaviour and it is not enough to actually overflow the stack. NCrunch sees the higher stack usage and thinks the stack is set to overflow, then you get your exception.
The best option here would just be to turn off the stack overflow detection. The configuration option you've found (Detect stack overflow) will do this, but you'll be wanting to turn it off for ALL the projects in your solution instead of just one of them (as the tracking code could throw from any of them). Setting it at solution level when in advanced configuration mode would make this easier.
NCrunch intercepts stack overflows by tracking the size of the overall stack and throwing an exception when it reaches a certain threshold. This process is not as perfect as I'd like it to be, owing that the acceptable stack size seems to be extremely variable depending on the context and we end up trying to guess at when it is highly likely to occur.
My first guess is that you have code that is running up the stack significantly, but it is probably normal behaviour and it is not enough to actually overflow the stack. NCrunch sees the higher stack usage and thinks the stack is set to overflow, then you get your exception.
The best option here would just be to turn off the stack overflow detection. The configuration option you've found (Detect stack overflow) will do this, but you'll be wanting to turn it off for ALL the projects in your solution instead of just one of them (as the tracking code could throw from any of them). Setting it at solution level when in advanced configuration mode would make this easier.
Aha, disabling the stack overflow detection for all projects did indeed result in no StackOverflowDetectedException being thrown.
I'm still curious exactly what we're doing that is running up the stack so much that it triggers NCrunch to detect an overflow...
But, I can continue my work through NCrunch now, so that's good.
Thanks!
I'm still curious exactly what we're doing that is running up the stack so much that it triggers NCrunch to detect an overflow...
But, I can continue my work through NCrunch now, so that's good.
Thanks!
Remco NCrunch Developer
#16224
02 Aug 2022 00:38 UTC
TobiasvdVen wrote:Aha, disabling the stack overflow detection for all projects did indeed result in no StackOverflowDetectedException being thrown.
I'm still curious exactly what we're doing that is running up the stack so much that it triggers NCrunch to detect an overflow...
But, I can continue my work through NCrunch now, so that's good.
Thanks for confirming that this got rid of the issue for you.
I'm also curious about why this is tripping the exception without any obvious reason. It may be due to the characteristics of the environment. If you manage to reproduce it in code that you can share with me, please do let me know.
Post a reply
Log in to reply.