Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

StackOverflowDetectedException in NCrunch, but test passes in other runners
TobiasvdVen
#1 Posted : Friday, July 29, 2022 9:55:35 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/18/2022(UTC)
Posts: 2
Location: Denmark

Thanks: 1 times
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?
Remco
#2 Posted : Saturday, July 30, 2022 12:16:25 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
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.
1 user thanked Remco for this useful post.
TobiasvdVen on 8/1/2022(UTC)
TobiasvdVen
#3 Posted : Monday, August 1, 2022 12:27:18 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/18/2022(UTC)
Posts: 2
Location: Denmark

Thanks: 1 times
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!
Remco
#4 Posted : Tuesday, August 2, 2022 12:38:18 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
TobiasvdVen;16223 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.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.039 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download