chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
+1 vote

Hello! We using StackExcange.Redis in our project. But if I run next test 

[TestMethod, Isolated]
public void ConnectAsync_ReturnConnection()
{
       var result = ConnectionMultiplexer

.ConnectAsync(\"192.168.0.1:80\")

.Result;
}

I get Typemock.StackOverflowException.

I see next stack trace in log file:

 Fatal error terminating. TypeMock.StackOverflowException: 
*** Potential StackOverflow detected. Typemock Isolator prevented application crash.
   at TypeMock.MockManager.isMocked(Object context, String typeName, String methodName, Object methodParameters, Boolean isDecorated, Boolean isIntercepted)
   at Typemock.Interceptors.Profiler.InternalMockManager.isMocked(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected, Boolean isIntercepted)
   at StackExchange.Redis.SocketManager.<>c.<.cctor>b__49_0(Object context)
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart(Object obj)

What can cause this exception?

asked by (620 points)

1 Answer

+1 vote

Hello! 

Since Isolator works with its own stack inside it needs space for it. The minimal requirement for stack size is more than 256 Kilobytes (more, not equal).

If we look at stack trace we see only one non-Typemock line: StackExchange.Redis.SocketManager.<>c.<.cctor>b__49_0(Object context)

As we can see in the source code of SocketManager, a new Thread is created with maxStackSize 32KB. Thus it causes StackOveflowException.

We can suggest to modify the Redis code in

StackExchange.Redis/StackExchange.Redis/StackExchange/Redis/SocketManager.cs - line 145

from: 

`var dedicatedWriter = new Thread(writeAllQueues, 32 * 1024);`

to: 

`var dedicatedWriter = new Thread(writeAllQueues, 512 * 1024);`

or 

`var dedicatedWriter = new Thread(writeAllQueues);`

answered by (3.9k points)
...