[12.x] keep single NotificationSender instance#58452
Merged
taylorotwell merged 2 commits intolaravel:12.xfrom Jan 21, 2026
Merged
[12.x] keep single NotificationSender instance#58452taylorotwell merged 2 commits intolaravel:12.xfrom
taylorotwell merged 2 commits intolaravel:12.xfrom
Conversation
Contributor
Author
|
Should we remove the guard logic (listener, instance variable) from the And request 3rd-party channel drivers to not dispatch the If so, I can send a PR. |
Contributor
|
This change breaks in Laravel Octane on the second request when the notification has the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR #55507, authored by me, added logic to ensure the
Illuminate\Notifications\Events\NotificationFailedis dispatched whenever a notification failed and also guard against double sending the same event in case a 3rd-party channel was already manually dispatching that event.As noted by discussion #58434, the
Illuminate\Notifications\ChannelManageralwaysnewup a new instance of theIlluminate\Notifications\NotificationSenderclass, and as such, a new listener for theIlluminate\Notifications\Events\NotificationFailedis registered times for each instance.In a case where multiple notifications are sent, but then down the road one fails, those multiple listeners were invoked.
The current approach also prevents garbage collection of the
Illuminate\Notifications\NotificationSenderinstances, as the registered listener would prevent those instances from being collected/destructed.In a scenario where an artisan command is scheduled to send multiple notifications for several users, that could lead to a memory overflow.
This PR
Illuminate\Notifications\NotificationSenderon theIlluminate\Notifications\ChannelManager.Illuminate\Notifications\NotificationSenderinstance is just called once even after multiple notifications were sent.Notes:
Illuminate\Notifications\ChannelManageris already registered as a singleton, that will only instantiate a singleIlluminate\Notifications\NotificationSenderinstance per life cycle.Illuminate\Notifications\NotificationSenderinstance, only one listener is regThanks @macropay-solutions for the heads-up.