Skip to content
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

Fix memory leaks #181

Merged
merged 3 commits into from Apr 13, 2021
Merged

Fix memory leaks #181

merged 3 commits into from Apr 13, 2021

Conversation

themsaid
Copy link
Member

@themsaid themsaid commented Apr 12, 2021

This PR fixes memory leaks in Octane as reported in #171


$sandbox->flush();

This will flush the entire sandbox container. This will clear any references to request-content singletons which allows PHP's garbage collector from clearing the memory when unset($sandbox) is called.


$this->app->make('view.engine.resolver')->forget('blade');
$this->app->make('view.engine.resolver')->forget('php');

These lines deal with a memory leak in facade/ignition as explained in laravel/framework#36955.

@themsaid themsaid mentioned this pull request Apr 12, 2021
@taylorotwell
Copy link
Member

@themsaid looks like our tests need fixing.

@themsaid
Copy link
Member Author

@taylorotwell the PR depends on laravel/framework#36955 so it'll be fixed when we can lock to the release tomorrow.

src/Worker.php Outdated Show resolved Hide resolved
@@ -110,6 +111,11 @@ public function handle(Request $request, RequestContext $context): void
} catch (Throwable $e) {
$this->handleWorkerError($e, $sandbox, $request, $context, $responded);
} finally {
$sandbox->flush();

$this->app->make('view.engine.resolver')->forget('blade');
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to forget all? If not, could it be added to Laravel today. Otherwise, other custom things will still cause leaks.

@taylorotwell taylorotwell merged commit 654cec9 into master Apr 13, 2021
@taylorotwell taylorotwell deleted the fixMemoryLeaks branch April 13, 2021 14:24
@@ -110,6 +111,11 @@ public function handle(Request $request, RequestContext $context): void
} catch (Throwable $e) {
$this->handleWorkerError($e, $sandbox, $request, $context, $responded);
} finally {
$sandbox->flush();
Copy link
Contributor

@albertcht albertcht Apr 13, 2021

Choose a reason for hiding this comment

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

Then it's okay to remove other sandbox' forgetInstance call in FlushTemporaryContainerInstances?
(Not sure if it's necessary to call forgetInstance in FlushAuthenticationState)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants