Skip to content

StackOverflowException when iterating through Redis keys #447

Closed
@rpmrmartin

Description

@rpmrmartin

Describe the bug
When our ASP.NET application iterates through all the keys on a Redis server, it causes the Datadog .NET Tracer to throw a StackOverflowException.

To Reproduce
Run the following code inside an application that is being profiled by the Datadog .NET Tracer:

using StackExchange.Redis;
ConnectionMultiplexer redis = RedisCaching.GetRedisMultiplexer();
IServer server = redis.GetServer("MyServer");
IEnumerator ide = server.Keys().GetEnumerator();
while (ide.MoveNext())
{
	// Do something
}

The exception is thrown when calling ide.MoveNext() for the first time

Expected behavior
The application should iterate over the keys without issue

Runtime environment (please complete the following information):

  • Instrumentation mode: Automatic with MSI installer
  • Tracer version: 1.5.0
  • OS: Found on Windows Server 2016, reproduced on Windows 10 Pro 1809
  • CLR: .NET Framework 4.7.2

Additional context
Stack trace:

<Repeat the last four calls ad infinitum>  

StackExchange.Redis.dll!StackExchange.Redis.RedisServer.ExecuteAsync<StackExchange.Redis.RedisBase.CursorEnumerable<StackExchange.Redis.RedisKey>.ScanResult>(StackExchange.Redis.Message message, StackExchange.Redis.ResultProcessor<StackExchange.Redis.RedisBase.CursorEnumerable<StackExchange.Redis.RedisKey>.ScanResult> processor, StackExchange.Redis.ServerEndPoint server) Line 577	C#  

Datadog.Trace.ClrProfiler.Managed.dll!Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.RedisBatch.ExecuteAsyncInternal<StackExchange.Redis.RedisBase.CursorEnumerable<StackExchange.Redis.RedisKey>.ScanResult>(object redisBase, object message, object processor, object server)	Unknown  

mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<StackExchange.Redis.RedisBase.CursorEnumerable<StackExchange.Redis.RedisKey>.ScanResult>.Start<Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.RedisBatch.<ExecuteAsyncInternal>d__7<StackExchange.Redis.RedisBase.CursorEnumerable<StackExchange.Redis.RedisKey>.ScanResult>>(ref Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.RedisBatch.<ExecuteAsyncInternal>d__7<StackExchange.Redis.RedisBase.CursorEnumerable<StackExchange.Redis.RedisKey>.ScanResult> stateMachine)	Unknown  

Datadog.Trace.ClrProfiler.Managed.dll!Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.RedisBatch.ExecuteAsyncInternal<StackExchange.Redis.RedisBase.CursorEnumerable<StackExchange.Redis.RedisKey>.ScanResult>(object redisBase, object message, object processor, object server)	Unknown  

StackExchange.Redis.dll!StackExchange.Redis.RedisServer.ExecuteAsync<StackExchange.Redis.RedisBase.CursorEnumerable<StackExchange.Redis.RedisKey>.ScanResult>(StackExchange.Redis.Message message, StackExchange.Redis.ResultProcessor<StackExchange.Redis.RedisBase.CursorEnumerable<StackExchange.Redis.RedisKey>.ScanResult> processor, StackExchange.Redis.ServerEndPoint server) Line 577	C#  

Datadog.Trace.ClrProfiler.Managed.dll!Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.RedisBatch.ExecuteAsyncInternal<StackExchange.Redis.RedisBase.CursorEnumerable<StackExchange.Redis.RedisKey>.ScanResult>(object redisBase, object message, object processor, object server)	Unknown  

mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<StackExchange.Redis.RedisBase.CursorEnumerable<StackExchange.Redis.RedisKey>.ScanResult>.Start<Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.RedisBatch.<ExecuteAsyncInternal>d__7<StackExchange.Redis.RedisBase.CursorEnumerable<StackExchange.Redis.RedisKey>.ScanResult>>(ref Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.RedisBatch.<ExecuteAsyncInternal>d__7<StackExchange.Redis.RedisBase.CursorEnumerable<StackExchange.Redis.RedisKey>.ScanResult> stateMachine)	Unknown  

Datadog.Trace.ClrProfiler.Managed.dll!Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.RedisBatch.ExecuteAsyncInternal<StackExchange.Redis.RedisBase.CursorEnumerable<StackExchange.Redis.RedisKey>.ScanResult>(object redisBase, object message, object processor, object server)	Unknown  

StackExchange.Redis.dll!StackExchange.Redis.RedisBase.CursorEnumerable<StackExchange.Redis.RedisKey>.GetNextPageAsync(StackExchange.Redis.IScanningCursor obj, long cursor, out StackExchange.Redis.Message message) Line 179	C#  

StackExchange.Redis.dll!StackExchange.Redis.RedisBase.CursorEnumerable<StackExchange.Redis.RedisKey>.CursorEnumerator.LoadNextPageAsync() Line 203	C#  

StackExchange.Redis.dll!StackExchange.Redis.RedisBase.CursorEnumerable<StackExchange.Redis.RedisKey>.CursorEnumerator.MoveNext() Line 258	C#  

<Our code>

The error happens every time on our test servers (Windows Server 2016 + IIS). On my development workstation (Windows 10 Pro 1809), the error usually happens when running the application from Visual Studio 2019 using IIS express, but not when using Local IIS.

(edit: formatting)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions