Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug toolbar data collector has infinite recursion when serializing a cyclic object #167

Open
mhvis opened this issue Jun 28, 2024 · 1 comment · May be fixed by #171
Open

Debug toolbar data collector has infinite recursion when serializing a cyclic object #167

mhvis opened this issue Jun 28, 2024 · 1 comment · May be fixed by #171

Comments

@mhvis
Copy link

mhvis commented Jun 28, 2024

We encountered this issue while using Symfony Live Components. We were (accidentally as part of a larger object) trying to insert a MountedComponent instance into a MongoDB collection. When the debug toolbar is active, we get an infinite recursion in the MongoQuerySerializer class.

Steps to reproduce:

  1. Have an object with a circular dependency:
class CyclicDependantObject
{
    private CyclicDependantObject $me;

    public function __construct()
    {
        $this->me = $this;
    }
}
  1. Insert it to a collection using a MongoDB Database.
class AController extends AbstractController
{
    #[Route('/endpoint', name: 'endpoint')]
    public function endpoint(#[Autowire(service: 'mongo.connection.symfony')] Database $database): Response
    {
        $database->createCollection('random');

        $collection = $database->selectCollection('random');

        $collection->insertOne(['cyclicObject' => new CyclicDependantObject()]);

        return new Response('Data inserted');
    }
}
@ilario-pierbattista
Copy link
Member

hi @mhvis thanks for reporting this.

Adding a maxdepth arg to this function \Facile\MongoDbBundle\DataCollector\MongoQuerySerializer::prepareUnserializableData should probably be enough to stop the endless recursion.

Having a unit test to reproduce this would be great.

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

Successfully merging a pull request may close this issue.

2 participants