From 6ca48ae60149f422b0263820cacbe5b77beb5cf3 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Wed, 4 Nov 2026 13:50:36 +0100 Subject: [PATCH] Fix memory leak of previous applications Laravel's ContextServiceProvider registers a queue payload callback referencing the application on every boot. Since Queue::$createPayloadCallbacks is static and the connector boots a new application for every request, every application stayed in memory until the end of the run. Clear the callbacks before booting a new application, like Laravel's TestCase does in tearDown(). Co-Authored-By: Claude Opus 5.5 --- src/Codeception/Lib/Connector/Laravel.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Codeception/Lib/Connector/Laravel.php b/src/Codeception/Lib/Connector/Laravel.php index 2bdad83..55bd395 100644 --- a/src/Codeception/Lib/Connector/Laravel.php +++ b/src/Codeception/Lib/Connector/Laravel.php @@ -22,6 +22,7 @@ use Illuminate\Foundation\Bootstrap\RegisterProviders; use Illuminate\Http\Request; use Illuminate\Http\UploadedFile; +use Illuminate\Queue\Queue; use Symfony\Component\HttpFoundation\Request as SymfonyRequest; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelBrowser as Client; @@ -177,6 +178,10 @@ private function initialize(SymfonyRequest $request = null): void */ private function loadApplication(): AppContract { + // Booting the application appends callbacks that reference it to this static array, + // so it has to be cleared to let previous applications be garbage collected. + Queue::createPayloadUsing(null); + /** @var AppContract $app */ $app = require $this->module->config['bootstrap_file']; if ($this->module->config['environment_file'] !== '.env') {