-
Notifications
You must be signed in to change notification settings - Fork 57
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
Handle duplicated subscription created event #194
Handle duplicated subscription created event #194
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kinda feels like the wrong place for this. Presumably this can happen when paddle sends two requests at the same time. It'd be better to do INSERT IGNORE
on the subscription, or just catch the exception from the eloquent call.
@GrahamCampbell Not sure what you mean. If a |
That's not what the issue is. The issue is two requests come in, both check the DB and see it doesn't exist, then both try to do the insert. |
@GrahamCampbell I still don't follow... surely the second requests sees that the subscription has been added by the first request? |
Not if the first request has not gotten as far as doing the insert when the second does the select. |
@GrahamCampbell but that would be the same situation we're in right now. We're currently talking if the second request comes in at a later point. |
@GrahamCampbell Sorry if the description is not very clear. The issue is as @driesvints described, the first call can "fail" because of network, maybe a listener execution went wrong or even if you hit retry on The proposed approach mimics what already exists on: I thought of checking if there was a subscription first and then proceeding with the execution, but this could lead to Replay attacks, thus, just stopping the execution like the previous endpoints do is the safest option. |
If for any reason
subscription_created
webhook is called more than once and the subscription was created on the first one, the subsequent calls will return a 500 status error as a result of the unique constraint on paddle_id.This PR solves this issue by checking if the subscription exists before proceeding.