TAN-7554 Email bug: Sending manual campaigns twice#13675
Merged
sebastienhoorens merged 2 commits intomasterfrom Apr 23, 2026
Merged
TAN-7554 Email bug: Sending manual campaigns twice#13675sebastienhoorens merged 2 commits intomasterfrom
sebastienhoorens merged 2 commits intomasterfrom
Conversation
When sending to large recipient lists, the HTTP request can time out (504) while the backend continues processing. The frontend shows an error and still displays the Send button, allowing users to trigger a second send — resulting in duplicate emails to all recipients. Introduce SendManualCampaignService that checks sent? inside a pessimistic row lock, making the check-then-send atomic. The existing policy check (CampaignPolicy#update?) runs before the lock is acquired, so concurrent requests can both pass it while deliveries from the first request are still uncommitted. Also decouple do_send? from update? in CampaignPolicy so the "prevent double send" concern lives only in the service, while "prevent editing sent campaigns" stays in the policy. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Collaborator
|
jamesspeake
approved these changes
Apr 23, 2026
Contributor
jamesspeake
left a comment
There was a problem hiding this comment.
Looks reasonable to me
| describe EmailCampaigns::SendManualCampaignService do | ||
| subject(:service) { described_class.new } | ||
|
|
||
| let(:user) { create(:admin) } |
Contributor
There was a problem hiding this comment.
Might be clearer that this is the triggering user
Suggested change
| let(:user) { create(:admin) } | |
| let(:current_user) { create(:admin) } |
Contributor
Author
There was a problem hiding this comment.
In this case I tend to disagree. The service implements a "use case" (business logic) that is meant to be decoupled from controller logic. "current_user" is a name typically used in controllers and not in the rest of the code, that's why I would argue the name doesn't really belong here.
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.
When sending to large recipient lists, the HTTP request can time out (504) while the backend continues processing. The frontend shows an error and still displays the Send button, allowing users to trigger a second send and resulting in duplicate emails to all recipients.
There are at least 5 issues:
Changelog
Fixed
[TAN-7554] Initial fix to prevent sending manual campaigns twice.