8000 Free reserved memory before handling fatal errors (#42630) · laravel/framework@5094350 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5094350

Browse files
authored
Free reserved memory before handling fatal errors (#42630)
When the PHP process exceeds the configured memory limit, a fatal error such as the following occurs: ``` Allowed memory size of 1073741824 bytes exhausted (tried to allocate 3358976 bytes) ``` Currently, the process abruptly exits in such cases without and indication as to what has caused the error. This is because the handler from `register_shutdown_function()` attempts to instantiate a `FatalError` instance, thus trying to use memory that is not available. This clears the reserved memory before this instantiation, thus ensuring that the process has enough memory to properly handle the error. Reserved memory is also cleared in `handleException` in the same way.
1 parent 51efb37 commit 5094350

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Illuminate/Foundation/Bootstrap/HandleExceptions.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ protected function ensureNullLogDriverIsConfigured()
159159
*/
160160
public function handleException(Throwable $e)
161161
{
162-
try {
163-
self::$reservedMemory = null;
162+
self::$reservedMemory = null;
164163

164+
try {
165165
$this->getExceptionHandler()->report($e);
166166
} catch (Exception $e) {
167167
//
@@ -217,6 +217,8 @@ public function handleShutdown()
217217
*/
218218
protected function fatalErrorFromPhpError(array $error, $traceOffset = null)
219219
{
220+
self::$reservedMemory = null;
221+
220222
return new FatalError($error['message'], 0, $error, $traceOffset);
221223
}
222224

0 commit comments

Comments
 (0)
0