-
Notifications
You must be signed in to change notification settings - Fork 55
Reset counter on reconnect or rollback failure #748
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
Conversation
WalkthroughCommit control flow was restructured to consolidate the nested-transaction check; rollback now resets the Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant SQL as SQL Adapter
participant PDO
Note over SQL: commitTransaction (new flow)
Caller->>SQL: commitTransaction()
SQL->>PDO: check PDO inTransaction(true?)
alt PDO not in transaction
SQL->>SQL: decrement inTransaction? (if >1) and return true
else PDO in transaction
SQL->>PDO: commit()
SQL->>SQL: decrement inTransaction and return result
end
sequenceDiagram
participant Caller
participant SQL as SQL Adapter
participant PDO
Note over SQL: rollbackTransaction error path
Caller->>SQL: rollbackTransaction()
SQL->>PDO: rollback()
alt PDOException thrown
SQL->>SQL: set inTransaction = 0
SQL-->>Caller: throw DatabaseException
else success
SQL->>SQL: set inTransaction appropriately
SQL-->>Caller: return true
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/Database/Adapter/SQL.php (1)
101-102: Consider resetting counter on commit failure for consistency.For consistency with the rollback error handling (line 130), consider resetting
inTransactionto 0 when commit fails. If a commit throws a PDOException, the transaction state is uncertain (typically rolled back by the database), and maintaining the counter could lead to inconsistent state tracking.Apply this diff to improve consistency:
try { $result = $this->getPDO()->commit(); $this->inTransaction = 0; } catch (PDOException $e) { + $this->inTransaction = 0; throw new TransactionException('Failed to commit transaction: ' . $e->getMessage(), $e->getCode(), $e); }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
composer.lockis excluded by!**/*.lock
📒 Files selected for processing (1)
src/Database/Adapter/SQL.php(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/Database/Adapter/SQL.php (1)
src/Database/Adapter.php (1)
inTransaction(366-369)
🔇 Additional comments (3)
src/Database/Adapter/SQL.php (3)
93-96: LGTM! Simplified nested transaction handling.The control flow simplification correctly handles nested transactions by decrementing the counter and returning early when
inTransaction > 1, deferring the actual PDO commit to the outermost transaction level.
130-130: LGTM! Correct error handling for rollback failure.Resetting
inTransactionto 0 when rollback fails is essential because the transaction state becomes uncertain after a rollback exception. This prevents the adapter from maintaining stale transaction state.
154-154: LGTM! Essential counter reset after reconnection.Resetting
inTransactionto 0 after reconnecting is critical because the new database connection has no transaction state from the previous connection. This prevents the adapter from incorrectly assuming an active transaction exists.
Summary by CodeRabbit