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

Maximum function nesting level of '256' reached with retryable http client and mailer handler #38970

Closed
BoShurik opened this issue Nov 3, 2020 · 3 comments

Comments

@BoShurik
Copy link
Contributor

BoShurik commented Nov 3, 2020

Symfony version(s) affected: 5.2.0-BETA3

Description

monolog:
    handlers:
        mail:
            type: fingers_crossed
            action_level: error
            excluded_http_codes: [ 400, 403, 404 ]
            handler: deduplicated
        deduplicated:
            type: deduplication
            handler: mailer
        mailer:
            type: symfony_mailer
            from_email: '%env(resolve:EMAIL_SENDER)%'
            to_email: '%env(EMERGENCY_EMAIL)%'
            subject: 'An Error Occurred! %%message%%'

and

framework:
    http_client:
        default_options:
            retry_failed:
                http_codes: [ 429 ]

leads to

 Maximum function nesting level of '256' reached, aborting!

on

bin/console cache:clear --env=prod

How to reproduce
https://github.com/BoShurik/retriyable-http-client-issue

@Nyholm
Copy link
Member

Nyholm commented Nov 3, 2020

I can confirm the issue. Here is a stack trace:

Screenshot 2020-11-03 at 13 19 32

@jderusse
Copy link
Member

jderusse commented Nov 3, 2020

For the record, there is a call loop when loading services symfony_mailer (that require HttpClient) and retryable_httpclient (that require the logger)

The loop occurs when the Mailer transportFactory have to parse the DSN.
Full loop is:
load Mailer log handler service -> Mailer Transport -> Parse env variable -> Load XXTransportFactoryService -> load RetryableService -> load Logger Service -> load Mailer log handler service

note: same issue without my "circular reference optimization patch"

@BoShurik
Copy link
Contributor Author

BoShurik commented Nov 3, 2020

Workaround is
composer req proxymanagerbridge

class Kernel extends BaseKernel implements CompilerPassInterface
{
    // ...

    public function process(ContainerBuilder $container)
    {
        $definition = $container->findDefinition('http_client');
        $definition->setLazy(true);
    }
}

nicolas-grekas added a commit that referenced this issue Nov 5, 2020
…+ Lazy Iterrator (jderusse)

This PR was merged into the 4.4 branch.

Discussion
----------

[DependencyInjection] Fix circular reference with Factory + Lazy Iterrator

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #38970
| License       | MIT
| Doc PR        | -

The issue, occurs when a `factory` iterates over services (think tagged iterator) that also need the `factory`.
The PhpDumper is not able to detect the loop because the TaggedService iterator is flaged as "lazy" which is ignored in the loop detection. https://github.com/symfony/symfony/blob/2d7e0b02c6dd8d652fe3732d0dd29f24bda1bddc/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php#L474-L476

See test case for a reproduce case.

This PR takes into account lazy services when computing loops.

I'm not sure this is the right thing to do /cc @nicolas-grekas .
A better solution could be to do this ONLY when the service is used as a factory?

Commits
-------

51ff060 Fix circular referene with Factory and LazyIterator
derrabus added a commit that referenced this issue Nov 12, 2020
… paths (jderusse)

This PR was merged into the 4.4 branch.

Discussion
----------

[DependencyInjection] Fix circular detection with multiple paths

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #39056
| License       | MIT
| Doc PR        | -

There are currently 2 kind of issues related to the Dependency Injection:

1. performance issue when project contains many loops (#37850)
Which has been fixed by #38882

2. Infinity loop in some case (#38970)
Which has been fixed by #38980 and #39021

The new issue #39056 has been introduced by #38882 (The performance issue refactor) because in order to optimize loop detection, I take a short cut and choose to not collect ALL the circular loop but only the one that matters

I was wrong. All loops matters.

This PR fix my previous refacto to collect ALL the paths, with a low CPU footprint

Commits
-------

1c3721e Fix circular detection with multiple paths
nicolas-grekas added a commit that referenced this issue Nov 27, 2020
…truct loop (jderusse)

This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

[DependencyInjection] Fix circular in DI with lazy + byContruct loop

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #39120
| License       | MIT
| Doc PR        | -

This fix another issue lazy service.
It partially revert #38980 and #39021

Initially, we trusted lazy services to be lazy and not beeing called while building the services graph
=> bug #38970 when lazy deps is injected in a factory, it may be consumed directly to build the object before the graph is fully built
Fixed by #38980 => lazy service are considered as "normal service"
=> bug #39015 some loop are not resolvable with "normal service", but it shouldn't be an issue when servie proxifyied
Fixed by #39021 => lazy service are considered as "normal service" except when proxyfied
=> bug #39120 some loop are not resolvable with "normal service", but it shouldn't be an issue because the lazy service is injected in the constructor and user

Fixed by this PR => that revert to the initial state. lazy service are trusted.
But now, The IterratorArgument injected in a factory (single exception) is not more considered as lazy

Commits
-------

54af139 [DependencyInjection] Fix circular in DI with lazy + byContruct loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants