Skip to content
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

Rollback existing transactions after request ended #912

Closed
wants to merge 1 commit into from
Closed

Rollback existing transactions after request ended #912

wants to merge 1 commit into from

Conversation

vatsake
Copy link

@vatsake vatsake commented Jun 18, 2024

When the script ends or when a connection is about to be closed, if you have an outstanding transaction, PDO will automatically roll it back. This is a safety measure to help avoid inconsistency in the cases where the script terminates unexpectedly--if you didn't explicitly commit the transaction, then it is assumed that something went awry, so the rollback is performed for the safety of your data.

PHP PDO transactions

Since Octane never actually quits, the transaction will still exist after the request has ended.

Consider the following code:

DB::beginTransaction();
User::create(['name' => $request->input('name')]);
if (someCondition()) {
   abort(403);
)
DB::commit();

If for some reason someCondition() is true, the request is aborted, but the transaction is not ended.
If the user tries again and someCondition() is false, then both the new and previous 'User' model is created.

Fixes
#909

Unfortunately I don't know how to test this. Hopefully someone will add it.

@taylorotwell
Copy link
Member

I would add this to your own application if you need it.

@driesvints
Copy link
Member

Sorry @vatsake. Seems like we're not going to make this change in core atm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants