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

Cross-reference alias for a service produces endless loop in php process #25338

Closed
leotiger opened this issue Dec 5, 2017 · 3 comments
Closed

Comments

@leotiger
Copy link

leotiger commented Dec 5, 2017

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? yes
Symfony version 3.4.1

It's possible to produce an endless loop in the underlying php process by establishing an alias cross-reference for a service in the services.yml. This is a sample portion that should allow to reproduce this behavior:

    # default configuration for services in *this* file
    _defaults:
        # automatically injects dependencies in your services
        autowire: true
        # automatically registers your services as commands, event subscribers, etc.
        autoconfigure: true
        # this means you cannot fetch services directly from the container via $container->get()
        # if you need to do this, you can override this setting on individual services
        public: false

    @app.something_doing: "@AppBundle\Something\DoesSomething"
    AppBundle\Something\DoesSomething: "@app.something_doing"

    AppBundle\:
        resource: '../../src/AppBundle/*'
        exclude: '../../src/AppBundle/{Entity,Repository,Tests,Something}'

    AppBundle\Controller\:
        resource: '../../src/AppBundle/Controller'
        public: true
        tags: ['controller.service_arguments']

    AppBundle\Something\DoesSomething:
        arguments: ["@mailer", "@router"]
        public: true

This breaks, at least in my setup, the composer update command as well as console commands, php process runs hot and never terminates. Probably the validator for the service definitions should check this to avoid the problem if you can reproduce it.

@leotiger leotiger changed the title Cross-reference alias produces endless loop in php process Cross-reference alias for a service produces endless loop in php process Dec 5, 2017
@sroze
Copy link
Contributor

sroze commented Dec 6, 2017

Yep, I can reproduce with just the following:

    app.test_class: "@App\\TestClass"
    App\TestClass: "@app.test_class"

(and something using App\TestClass)

@sroze
Copy link
Contributor

sroze commented Dec 6, 2017

Fixed in #25364

@leotiger
Copy link
Author

leotiger commented Dec 7, 2017

@sroze,

I've tested your fix and it works as expected throwing a circular reference exception. Thx.

fabpot added a commit that referenced this issue Dec 7, 2017
… `findDefinition` method (sroze)

This PR was merged into the 3.3 branch.

Discussion
----------

[DependencyInjection] Prevent a loop in aliases within the `findDefinition` method

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #25338
| License       | MIT
| Doc PR        | ø

This prevents an infinite loop going when aliases reference themselves. This is based on 3.3 as the "normalized ID" changed to allow non-lowercase names. Fixing this in 2.7 would mean a merge conflict that IMO is not worth it.

Commits
-------

22f3523 Prevent a loop in aliases within the `findDefinition` method
@fabpot fabpot closed this as completed Dec 7, 2017
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

5 participants