Reputation: 2989
My problem is some code that is getting called in a reentrant way which is causing it to crash and trying to debug how it can possibly be called by 2 threads or reentrant with the same thread. I added a log that gives the Environment.StackTrace and this is what it got at the end of this message.
My confusion is after the line:
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Those seem like the top or beginning of any stack. But notice that the stack trace actually begins before those lines. In fact, line previous to those above is this:
at TickZoom.MBTFIX.MBTFIXSimulator.OnTick(Message quoteMessage, SymbolInfo symbol, Tick tick) in C:\Local\TickZoom\Project\Public\Providers\MBTFIX\MBTFIXProvider\MBTFIX\MBTFIXSimulator.cs:line 481
Here's the line 481:
if( trace) log.Trace("Sending tick: " + tick);
But that line is just a log message and can't in any possible way call System.Threading.ThreadHelper.ThreadStart(). So how does this crazy stack trace exist?
at TickZoom.MBTFIX.MBTFIXSimulator.OnTick(Message quoteMessage, SymbolInfo symbol, Tick tick) in C:\Local\TickZoom\Project\Public\Providers\MBTFIX\MBTFIXProvider\MBTFIX\MBTFIXSimulator.cs:line 479
at TickZoom.FIX.FIXServerSymbolHandler.ProcessOnTickCallBack() in C:\Local\TickZoom\Project\Public\Providers\Common\ProviderUtil\FIX\FIXServerSymbolHandler.cs:line 301
at TickZoom.Threading.TaskLoop.Run() in C:\Local\TickZoom\Project\Engine\Parallel\TaskBase.cs:line 669
at TickZoom.Threading.TaskBase.Execute(ThreadInfo thread) in C:\Local\TickZoom\Project\Engine\Parallel\TaskBase.cs:line 213
at TickZoom.Threading.ParallelManager.ExecuteTasks(ThreadInfo thread) in C:\Local\TickZoom\Project\Engine\Parallel\ParallelManager.cs:line 685
at TickZoom.Threading.ParallelManager.Run() in C:\Local\TickZoom\Project\Engine\Parallel\ParallelManager.cs:line 632
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
at TickZoom.MBTFIX.MBTFIXSimulator.OnTick(Message quoteMessage, SymbolInfo symbol, Tick tick) in C:\Local\TickZoom\Project\Public\Providers\MBTFIX\MBTFIXProvider\MBTFIX\MBTFIXSimulator.cs:line 481
at TickZoom.FIX.FIXServerSymbolHandler.ProcessOnTickCallBack() in C:\Local\TickZoom\Project\Public\Providers\Common\ProviderUtil\FIX\FIXServerSymbolHandler.cs:line 301
at TickZoom.Threading.TaskLoop.Run() in C:\Local\TickZoom\Project\Engine\Parallel\TaskBase.cs:line 669
at TickZoom.Threading.TaskBase.Execute(ThreadInfo thread) in C:\Local\TickZoom\Project\Engine\Parallel\TaskBase.cs:line 213
Upvotes: 1
Views: 681
Reputation: 21729
As in the comments to your question, weird stack traces such as this arise when one or more stack traces are output right after one another:
Log.WriteLine(Environment.StackTrace)
try
{
SomethingThatThrowsAnException();
}
catch (Exception e)
{
Log.WriteLine(e.StackTrace); // better to do Log.WriteLine(e) to get the message
}
Upvotes: 2