Skip to content

Possible recursion detected (offset: 5 level(s)) #61

@inethui

Description

@inethui

When I tried to serialize a large object graph with many levels of references, I got the exception "Possible recursion detected (offset: 5 level(s))".

It failed to handle an object which has 6 levels of inheritance.

I debugged into Aqla code, it seems that the object's levels of references, before reaching the object which has 6 level of inheritance, has exceeded 25.

In "ProtoWriter.StartSubItem", when writer._depth is greater than RecursionCheckDepth (which is hardcoded as 25), writer.CheckRecursionStackAndPush is called. If the instance has 6 levels of inheritance, each of them is handled by a different TypeSerializer, "CheckRecursionStackAndPush" will be called 6 times on the same object instance, and this would exceed the limit 5, and would trigger the following code and throw an exception:

            if (_recursionStack.HasReferences(instance, 5))
            {
                hitLevel = _recursionStack.IndexOfReference(instance);
                throw new ProtoException("Possible recursion detected (offset: " + (_recursionStack.Count - hitLevel).ToString() + " level(s)): " + instance.ToString());
            }

I'm wondering why it checks against 5 recursions. Is this number configurable? Also, why RecursionCheckDepth is 25, and is it configurable?

Thanks

Hui Lin

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions