8000 bug #29376 [EventDispatcher] Fix eventListener wrapper loop in Tracea… · symfony/symfony@fb4b75d · GitHub
[go: up one dir, main page]

Skip to content

Commit fb4b75d

Browse files
bug #29376 [EventDispatcher] Fix eventListener wrapper loop in TraceableEventDispatcher (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
2 parents 5d0c93b + 3830a9e commit fb4b75d

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,24 @@ public function dispatch($eventName, Event $event = null)
132132
}
133133

134134
$this->preProcess($eventName);
135-
$this->preDispatch($eventName, $event);
136-
137-
$e = $this->stopwatch->start($eventName, 'section');
138-
139-
$this->dispatcher->dispatch($eventName, $event);
140-
141-
if ($e->isStarted()) {
142-
$e->stop();
135+
try {
136+
$this->preDispatch($eventName, $event);
137+
try {
138+
$e = $this->stopwatch->start($eventName, 'section');
139+
try {
140+
$this->dispatcher->dispatch($eventName, $event);
141+
} finally {
142+
if ($e->isStarted()) {
143+
$e->stop();
144+
}
145+
}
146+
} finally {
147+
$this->postDispatch($eventName, $event);
148+
}
149+
} finally {
150+
$this->postProcess($eventName);
143151
}
144152

145-
$this->postDispatch($eventName, $event);
146-
$this->postProcess($eventName);
147-
148153
return $event;
149154
}
150155

0 commit comments

Comments
 (0)
0