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

Reset application scope to flush scoped instances #313

Merged
merged 6 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Listeners/FlushTemporaryContainerInstances.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ class FlushTemporaryContainerInstances
*/
public function handle($event): void
{
if (method_exists($event->app, 'resetScope')) {
$event->app->resetScope();
}

foreach ($event->sandbox->make('config')->get('octane.flush', []) as $binding) {
$event->app->forgetInstance($binding);
$event->sandbox->forgetInstance($binding);
Copy link
Member

Choose a reason for hiding this comment

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

Would this be a breaking change?

Copy link
Member Author

@themsaid themsaid Jun 10, 2021

Choose a reason for hiding this comment

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

No, we already flush the entire sandbox after each operation:

https://github.com/laravel/octane/blob/1.x/src/Worker.php#L114

}
}
}
4 changes: 4 additions & 0 deletions src/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ public function handleTask($data)

return TaskExceptionResult::from($e);
} finally {
$sandbox->flush();

// After the request handling process has completed we will unset some variables
// plus reset the current application state back to its original state before
// it was cloned. Then we will be ready for the next worker iteration loop.
Expand All @@ -177,6 +179,8 @@ public function handleTick(): void
} catch (Throwable $e) {
$this->dispatchEvent($sandbox, new WorkerErrorOccurred($e, $sandbox));
} finally {
$sandbox->flush();

unset($sandbox);

CurrentApplication::set($this->app);
Expand Down