-
Notifications
You must be signed in to change notification settings - Fork 89
Fix for #83: misconfigured aliases can lead to infinite loops #89
Fix for #83: misconfigured aliases can lead to infinite loops #89
Conversation
…eNotFoundException` at runtime
…ait`, as it is common to `ServiceManager` and `AbstractPluginManager`
… loops by skipping alias resolution for already visited aliases
Nice, clean solution. Would be nice if we hit a cyclic structure, but just being told it cannot resolve is reasonable, I think. 👍 |
you could detect it: when exiting the loop, check whether the final name appears in |
…o prevent silly mistakes with aliases
I provided a much more comprehensive exception, which is thrown at Hope that clears up all this :-) |
Should you really detect all cycles in the alias map when building the exception, or only the cycle being found at this point ? Your current logic means that each cycle is duplicated many times (the number of times is equal to the length of the cycle), making the user think there is 4 cycles in the map while there is actually only 1 (involving 4 items) |
Agreed, but I wanted to show all possible entry points. De-duplicating those is another piece of work. In general, my though-flow is following:
|
@Ocramius you could display only the cycle involving the service detected by the runtime IMO. Then, people would be able to fix cycles one after the other. Displaying the same cycle many times (letting the user determine that it is actually the same as the display is different and may not even be grouped together) makes debugging harder IMO. |
@stof I simply de-duplicated the cycles (see latest commits). Less confusing now, IMO :-) |
I'd love to see the use case for aliasing deeper then 100 :) |
How's about: /**
* Resolve all aliases to their canonical service names.
*/
private function resolveAliases(array $aliases)
{
foreach ($aliases as $alias => $service) {
$name = $alias;
$count = 0;
while (isset($this->aliases[$name]) && $count < 100) {
$name = $this->aliases[$name];
$count++;
}
if ($count > 99) {
throw new ExceptionalIdiotlException("This is nuts. Find another library.")
}
$this->resolvedAliases[$alias] = $name;
}
} |
@kynx correct solutions over approximate ones, IMO |
@Ocramius yeah, but please, please can't we squeak the |
Would love to, but it would violate some sort of yet to be invented CoC ;-) |
LGTM 👍 |
Really nice work, @Ocramius ! |
…n-lead-to-infinite-loops Fix for #83: misconfigured aliases can lead to infinite loops
Fixes #83