Skip to content

docs: Doctrine instability in long-running runtime #243

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

Closed
wants to merge 5 commits into from

Conversation

vasilvestre
Copy link

No description provided.

Copy link
Member

@dunglas dunglas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!!

vasilvestre and others added 3 commits October 5, 2023 15:12
Co-authored-by: Kévin Dunglas <[email protected]>
Co-authored-by: Kévin Dunglas <[email protected]>
Co-authored-by: Kévin Dunglas <[email protected]>
@vasilvestre vasilvestre requested a review from dunglas October 5, 2023 13:14
Co-authored-by: Jacob Dreesen <[email protected]>

## Doctrine ORM Issues

Running Symfony with a long-running runtime that leaves worker threads alive, such as the worker mode of FrankenPHP, Swoole or Roadrunner regularly leads to exceptions being thrown when fetching many entities (~100) with Doctrine, every few requests. The worker restarts itself when these exceptions are thrown.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Running Symfony with a long-running runtime that leaves worker threads alive, such as the worker mode of FrankenPHP, Swoole or Roadrunner regularly leads to exceptions being thrown when fetching many entities (~100) with Doctrine, every few requests. The worker restarts itself when these exceptions are thrown.
Running Symfony with a long-running runtime that leaves worker threads alive, such as the worker mode of FrankenPHP, Swoole or Roadrunner regularly leads to exceptions being thrown when fetching many entities (~100) with Doctrine. The worker restarts itself when these exceptions are thrown.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't happen on every request, only on subsequent ones. I have a calendar page traversing a lot of information from different entities with OneToMany relations. Every ~5-10 page visits, php throws a fatal error (typically Fatal Error, Nesting level too deep, recursive dependency?, but sometimes other ones). After reload, it's good for 5-10 visits again and so on.

(I know, I shouldn't use Doctrine for read-only purposes, but efficiency isn't terribly important as the requests still finishes in under 100ms)
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it would be nice to provide a workaround for that in the docs while it's not fixed upstream.
I'm pretty sure that registering a custom Symfony listener that will call ping() and/or reset the Doctrine connection before using it would fix the issue.

Copy link
Contributor

@henderkes henderkes Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've linked a fix in the issue. You can use the bundle, or just copy-paste the middleware into your own project.

https://github.com/Baldinof/roadrunner-bundle/blob/3.x/src/Integration/Doctrine/DoctrineORMMiddleware.php

Although, to be honest, I'm not sure why this fixes the issue with doctrine randomly causing bogus php error messages. The memory leak related to doctrine was already fixed sometime in the last months.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dunglas do you want to try and document the workaround before merging this PR ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DubbleClick I think that the Doctrine error is triggering another bug in Symfony Error Handler... Would be nice to investigate this one too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to investigate that further in the past, but it didn't really lead anywhere. What prevented the error was limiting the amount of entities I loaded with doctrine. What would be a bug in the Symfony error handler regarding this? That it still renders parts of the template before the crash?

@dunglas dunglas changed the title docs : doctrine instability in long-running runtime docs: Doctrine instability in long-running runtime Oct 5, 2023
@KDederichs
Copy link

Is still still an issue after the changes they merged regarding APP_RUNTIME_MODE?

@darkweak
Copy link

@KDederichs I still have the issue.

@phramz
Copy link

phramz commented Mar 1, 2024

I had similar issues with Doctrine and Symfony ... rebooting the kernel between requests fixed it in my case. See php-runtime/runtime#166

@dunglas
Copy link
Member

dunglas commented Apr 25, 2024

This is now fixed in Symfony! Thanks for your help @vasilvestre!!

symfony/symfony#53214

@dunglas dunglas closed this Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants