Skip to content

[EventDispatcher] Fix eventListener wrapper loop in TraceableEventDispatcher #29376

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

Merged
merged 1 commit into from
Dec 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,24 @@ public function dispatch($eventName, Event $event = null)
}

$this->preProcess($eventName);
$this->preDispatch($eventName, $event);

$e = $this->stopwatch->start($eventName, 'section');

$this->dispatcher->dispatch($eventName, $event);

if ($e->isStarted()) {
$e->stop();
try {
$this->preDispatch($eventName, $event);
try {
$e = $this->stopwatch->start($eventName, 'section');
try {
$this->dispatcher->dispatch($eventName, $event);
} finally {
if ($e->isStarted()) {
$e->stop();
}
}
} finally {
$this->postDispatch($eventName, $event);
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

}
} finally {
$this->postProcess($eventName);
}

$this->postDispatch($eventName, $event);
$this->postProcess($eventName);

return $event;
}

Expand Down