Skip to content

Commit aa7e187

Browse files
committed
[2.x] Fix queue worker TypeError on null connection name
illuminate/queue 13.15.0 type-hinted WorkerIdle::$connectionName as `string`. Flarum's queue worker resolves its connection name from config('queue.default') (the WorkCommand argument fallback), which Flarum never set, so the worker loop dispatched WorkerIdle(null, ...) and threw a TypeError on every idle tick. Set config('queue.default') to 'flarum' and give the queue connection a name via setConnectionName('flarum'), so the worker always receives a non-null string. This is a code fix rather than a version constraint: it works on illuminate/queue both before and after 13.15.0.
1 parent 1440d9f commit aa7e187

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

framework/core/src/Foundation/InstalledSite.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,16 @@ protected function getIlluminateConfig(): ConfigRepository
159159
'lifetime' => 120,
160160
'files' => $this->paths->storage.'/sessions',
161161
'cookie' => 'session'
162-
]
162+
],
163+
// Flarum uses a single queue connection bound as 'flarum.queue.connection'
164+
// rather than Laravel's named connections. The queue worker command falls
165+
// back to config('queue.default') when no connection argument is given, so
166+
// we provide a name here. Without it the name is null, which since
167+
// illuminate/queue 13.15.0 throws a TypeError from WorkerIdle's typed
168+
// string $connectionName in the worker loop.
169+
'queue' => [
170+
'default' => 'flarum',
171+
],
163172
]);
164173
}
165174

framework/core/src/Queue/QueueServiceProvider.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ public function register(): void
7373

7474
$queue->setContainer($container);
7575

76+
// Give the connection a name so events that carry it (e.g. WorkerIdle)
77+
// receive a string rather than null. illuminate/queue 13.15.0 type-hinted
78+
// WorkerIdle::$connectionName as `string`, so a null name now throws a
79+
// TypeError in the worker loop.
80+
$queue->setConnectionName('flarum');
81+
7682
return $queue;
7783
});
7884

framework/core/tests/integration/queue/QueueServiceProviderTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,39 @@ public function it_registers_queue_commands_for_database_driver()
9191
$this->assertContains(\Illuminate\Queue\Console\RetryCommand::class, $commandNames);
9292
}
9393

94+
/**
95+
* Regression test: the queue connection must have a non-null string name.
96+
*
97+
* illuminate/queue 13.15.0 type-hinted WorkerIdle::$connectionName as
98+
* `string`, so the worker loop throws a TypeError when the connection name
99+
* is null. The name flows from the queue connection / config('queue.default').
100+
*/
101+
#[Test]
102+
public function queue_connection_has_a_non_null_string_name()
103+
{
104+
$this->config('queue', ['driver' => 'database']);
105+
106+
$this->app();
107+
108+
$queue = $this->app()->getContainer()->make(Queue::class);
109+
110+
$this->assertIsString($queue->getConnectionName());
111+
$this->assertNotEmpty($queue->getConnectionName());
112+
}
113+
114+
#[Test]
115+
public function default_queue_connection_name_is_configured()
116+
{
117+
$this->app();
118+
119+
$default = $this->app()->getContainer()->make('config')->get('queue.default');
120+
121+
// The worker command falls back to this when no connection argument is
122+
// given; it must be a non-null string to satisfy WorkerIdle.
123+
$this->assertIsString($default);
124+
$this->assertNotEmpty($default);
125+
}
126+
94127
#[Test]
95128
public function it_uses_null_failed_job_provider_for_sync_queue()
96129
{

0 commit comments

Comments
 (0)