-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[8.x] Failed to send queued notifications with RateLimited
middleware: Exception: Serialization of 'Closure' is not allowed
#35868
Comments
You need to share the full stack trace. |
Please re-open with more information as noted by @themsaid |
Thank you for the notes. The full stack trace is attached as below: Exception {#7246
#message: "Serialization of 'Closure' is not allowed"
#code: 0
#file: "/app/vendor/laravel/framework/src/Illuminate/Queue/Queue.php"
#line: 157
trace: {
/app/vendor/laravel/framework/src/Illuminate/Queue/Queue.php:157 { …}
/app/vendor/laravel/framework/src/Illuminate/Queue/Queue.php:127 { …}
/app/vendor/laravel/framework/src/Illuminate/Queue/Queue.php:104 { …}
/app/vendor/laravel/framework/src/Illuminate/Queue/SyncQueue.php:38 { …}
/app/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:251 { …}
/app/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:227 { …}
/app/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:77 { …}
/app/vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php:212 { …}
/app/vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php:76 { …}
/app/vendor/laravel/framework/src/Illuminate/Notifications/ChannelManager.php:39 { …}
/app/vendor/laravel/framework/src/Illuminate/Notifications/RoutesNotifications.php:18 { …}
/app/vendor/psy/psysh/src/ExecutionLoopClosure.php:55 { …}
/app/vendor/psy/psysh/src/ExecutionLoopClosure.php:55 { …}
/app/vendor/psy/psysh/src/ExecutionClosure.php:96 { …}
/app/vendor/psy/psysh/src/Shell.php:370 { …}
/app/vendor/psy/psysh/src/Shell.php:341 { …}
/app/vendor/symfony/console/Application.php:166 { …}
/app/vendor/psy/psysh/src/Shell.php:316 { …}
/app/vendor/laravel/tinker/src/Console/TinkerCommand.php:81 { …}
/app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36 { …}
/app/vendor/laravel/framework/src/Illuminate/Container/Util.php:40 { …}
/app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:93 { …}
/app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:37 { …}
/app/vendor/laravel/framework/src/Illuminate/Container/Container.php:610 { …}
/app/vendor/laravel/framework/src/Illuminate/Console/Command.php:136 { …}
/app/vendor/symfony/console/Command/Command.php:255 { …}
/app/vendor/laravel/framework/src/Illuminate/Console/Command.php:121 { …}
/app/vendor/symfony/console/Application.php:971 { …}
/app/vendor/symfony/console/Application.php:290 { …}
/app/vendor/symfony/console/Application.php:166 { …}
/app/vendor/laravel/framework/src/Illuminate/Console/Application.php:93 { …}
/app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:129 { …}
/app/artisan:37 {
› $input = new Symfony\Component\Console\Input\ArgvInput,
› new Symfony\Component\Console\Output\ConsoleOutput
› );
arguments: {
$input: Symfony\Component\Console\Input\ArgvInput {#25 …}
$output: Symfony\Component\Console\Output\ConsoleOutput {#23 …}
}
}
}
} |
@taylorotwell @themsaid Is it possible that we re-open this? |
I see you're using Tinker. Are you maybe using the wrong way to send these jobs? |
RateLimited
middleware: Exception: Serialization of 'Closure' is not allowed
RateLimited
middleware: Exception: Serialization of 'Closure' is not allowed
@driesvints It wasn't from the |
Tried call
|
I think I see what's going on. You're using the framework's If you wrote the middleware as documented does the error still happen then? |
Just dig into #30070, it seems like public function middleware()
{
return [new RateLimited('notification-channel-xxx')];
} The use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
RateLimiter::for('notification-channel-xxx', function ($job) {
return Limit::perMinute(20);
});
} |
Hmm, I see. I'm not sure what the best solution here would be.. |
Maybe we can retrieve and instantiate middlewares after the job |
Fixed for PHP 7.4+ by this: f3d4dcb |
@chuangbo can you confirm the commit above fixes your issue? I see you are on PHP 7.4. |
@taylorotwell Thank you for the prompt fix! Good to know |
I think the same problem is for php 8.x (for me 8.0.6) and Laravel 8.x (for me 8.43.0). |
Description:
The notification channel we are using is limiting 20 requests per minute. Since job middleware are supported for queued notifications (#30070), we would like to leverage
Illuminate\Queue\Middleware\RateLimited
middleware for the queued notification, as described in https://laravel.com/docs/8.x/queues#rate-limiting. But it throws exception:Serialization of 'Closure' is not allowed
.Steps To Reproduce:
RateLimiter
in the boot method ofAppServiceProvider
The text was updated successfully, but these errors were encountered: