C#C
C#3y ago
34 replies
Hazel 🌊💃

❔ Stack Overflow Exception due to excessive cancellation token related method invocations?

I'm getting a stack overflow exception at unpredicable times and upon investigation in Rider's parallel stacks functionality I can see that pretty early on in my application I'm getting a rather verbose stack with a few calls related to cancellation token registration repeated over and over. What are some things I can begin investigating that might cause this behavior?

For context, I have
async/await
processing in place, and several areas where I have tasks spawning tasks for example:
List<Task> processingTasks = new();
foreach (var sample in samples) {
    var task = _processor.Process(sample, cancellationToken);
    processingTasks.Add(task);
}

await Task.WhenAll(processingTasks);

// in processor.process
List<Task> generationTasks = new();
foreach (var foo in sample.Foos) {
    var task = _generator.Generate(foo, cancellationToken);
    generationTasks.Add(task);
}

await Task.WhenAll(generationTasks);
image.png
Was this page helpful?