Maravel Framework 10.61 Prevents Circular Dependency
Home » Development  »  Maravel Framework 10.61 Prevents Circular Dependency

Maravel Framework 10.61 Prevents Circular Dependency


maravel-framework 10.61 prevents circular dependency.

Because the macroable classes are resolved from the container in Maravel-Framework, there are some corner cases like \Illuminate\Events\Dispatcher or Illuminate\Console\Scheduling\Schedule which if resolved from container would generate circular dependency that leads to segmentation fault or memory exhaustion.
This can happen also to developers leading to long debug time.

To shorten the detection of such cases, this version introduces a new config app.circular_dependency_memory_limitthat should be set greater than 0 in sandbox only to not impact the boot time:

/**
* Limit of extra memory used to detect circular dependencies when resolving an abstract from container (bytes)
* use 0 to disable or 10485760 for 10 MB
*/

'circular_dependency_memory_limit' => 0, 

Result:

Illuminate\Contracts\Container\CircularDependencyException

Circular dependency detected while resolving [Illuminate\Console\Scheduling\Schedule]. Memory limit difference reached or exceeded 10485760 bytes: {"Illuminate\\Console\\Scheduling\\Schedule":{"i":1798,"b":27262976}}

at vendor/macropay-solutions/maravel-framework/illuminate/Container/Container.php:886

This translates to:

When Illuminate\Console\Scheduling\Schedule starts to be resolved from container, the memory used by PHP, read via \memory_get_usage(true), was 27262976 bytes. Then the code went in an infinite loop until the memory difference exceeded 10 MB (10485760 bytes), meaning the memory used by PHP was greater or equal to 27262976 + 10485760 bytes. If not stopped, this would continue until a segmentation fault would trigger a hard to debug memory exhausted fatal error.


Note:

Both Maravelith and Maravel templates can take advantage of this improvement.

This is a second improvement after the di helper that does not call make on the container if it did not finish booting.