I think i found a bug in handling of queue jobs in Laravel. If I run laravel queue jobs with config cached in laravel, then runtime configs persists between jobs.
Expected result: Second job does not know of runtime config.
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class WriteToConfig implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
//write to config
config(['services.foobar' => 'hello']);
info('writing config value: ' . config('services.foobar') );
}
}
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class ReadRuntimeConfig implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
info('reading config value: ' . config('services.foobar') );
}
}
Route::get("test", function(){
dispatch(new \App\Jobs\WriteToConfig());
dispatch(new \App\Jobs\ReadRuntimeConfig());
});
- run command
php artisan config:clear
- start worker
php artisan queue:work --tries=1
- run jobs, by visiting /test route
[2020-01-08 13:03:40][13] Processing: App\Jobs\WriteToConfig
[2020-01-08 13:03:40][13] Processed: App\Jobs\WriteToConfig
[2020-01-08 13:03:58][14] Processing: App\Jobs\ReadRuntimeConfig
[2020-01-08 13:03:58][14] Processed: App\Jobs\ReadRuntimeConfig
[2020-01-08 13:03:42] local.INFO: writing config value: hello
[2020-01-08 13:04:00] local.INFO: reading config value:
- run command
php artisan config:cache
- start worker
php artisan queue:work --tries=1
- run jobs, by visiting /test route
[2020-01-08 13:03:40][13] Processing: App\Jobs\WriteToConfig
[2020-01-08 13:03:40][13] Processed: App\Jobs\WriteToConfig
[2020-01-08 13:03:58][14] Processing: App\Jobs\ReadRuntimeConfig
[2020-01-08 13:03:58][14] Processed: App\Jobs\ReadRuntimeConfig
[2020-01-08 13:03:42] local.INFO: writing config value: hello
[2020-01-08 13:04:00] local.INFO: reading config value: hello
As you see in Test2, the ReadRuntimeConfig
knows of the values "hello" which I think it should not. This is the potential bug.