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

[EventDispatcher] Fix eventListener wrapper loop in TraceableEventDispatcher #29376

Merged
merged 1 commit into from Dec 1, 2018

Conversation

Projects
None yet
4 participants
@jderusse
Copy link
Contributor

jderusse commented Nov 29, 2018

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets none
License MIT
Doc PR na

The TracableEventDispatcher wrap decorate (in the method preProcess) each listeners in a WrappedListener before delegating the dispatch to the real dispatcher, then remove the wrapper (in the method postProcess.

But, if a listener triggers an exception, the postProcess method is not called, and the wrapper in not removed.
If the same event is triggered a second time, the listeners will be decorated twice, etc, etc..
This is an issue with php-pm where the same event is triggered hundred of times within the same process.

This PR moves the postProcess in a finally block in order to be called even if an exception in thrown.

@jderusse jderusse changed the base branch from master to 3.4 Nov 29, 2018

@ro0NL

This comment has been minimized.

Copy link
Contributor

ro0NL commented Nov 30, 2018

👍 included this also in #29312

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Nov 30, 2018

@jderusse jderusse force-pushed the jderusse:fix-wrap-loop branch from d70a121 to a137088 Nov 30, 2018

@jderusse jderusse force-pushed the jderusse:fix-wrap-loop branch from a137088 to 3830a9e Nov 30, 2018

@ro0NL

ro0NL approved these changes Nov 30, 2018

@chalasr chalasr changed the title [EventDispatcher] Fix eventListener wrapper loop in TracableEventDispatcher [EventDispatcher] Fix eventListener wrapper loop in TraceableEventDispatcher Nov 30, 2018

}
}
} finally {
$this->postDispatch($eventName, $event);

This comment has been minimized.

@ro0NL

ro0NL Dec 1, 2018

Contributor

in #29312 i actually hesitated if we should call postDispatch after exception. That's a new behavior, where the user cant act upon as it doesnt know about an errored dispatch call.

This comment has been minimized.

@ro0NL

ro0NL Dec 1, 2018

Contributor

Hm, looking at

protected function postDispatch($eventName, Event $event)
{
switch ($eventName) {
case KernelEvents::CONTROLLER_ARGUMENTS:
$this->stopwatch->start('controller', 'section');
break;
case KernelEvents::RESPONSE:
$token = $event->getResponse()->headers->get('X-Debug-Token');
$this->stopwatch->stopSection($token);
break;
case KernelEvents::TERMINATE:
// In the special case described in the `preDispatch` method above, the `$token` section
// does not exist, then closing it throws an exception which must be caught.
$token = $event->getResponse()->headers->get('X-Debug-Token');
try {
$this->stopwatch->stopSection($token);
} catch (\LogicException $e) {
}
break;
}
}
it should be OK and expected.

@nicolas-grekas

This comment has been minimized.

Copy link
Member

nicolas-grekas commented Dec 1, 2018

Thank you @jderusse.

@nicolas-grekas nicolas-grekas merged commit 3830a9e into symfony:3.4 Dec 1, 2018

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
fabbot.io Your code looks good.
Details

nicolas-grekas added a commit that referenced this pull request Dec 1, 2018

bug #29376 [EventDispatcher] Fix eventListener wrapper loop in Tracea…
…bleEventDispatcher (jderusse)

This PR was merged into the 3.4 branch.

Discussion
----------

[EventDispatcher] Fix eventListener wrapper loop in TraceableEventDispatcher

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | none
| License       | MIT
| Doc PR        | na

The `TracableEventDispatcher` wrap decorate (in the method `preProcess`) each listeners in a `WrappedListener` before delegating the dispatch to the real dispatcher, then remove the wrapper (in the method `postProcess`.

But, if a listener triggers an exception, the `postProcess` method is not called, and the wrapper in not removed.
If the same event is triggered a second time, the listeners will be decorated twice, etc, etc..
This is an issue with php-pm where the same event is triggered hundred of times within the same process.

This PR moves the `postProcess` in a finally block in order to be called even if an exception in thrown.

Commits
-------

3830a9e Fix wrapped loop of event listener
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.