-
Notifications
You must be signed in to change notification settings - Fork 89
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
fix txContext auto-cancellation of context #4012
Conversation
Important Auto Review SkippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Can you provide a link to the CI failure that motivates this change?
defer func() { | ||
// Attempt to rollback the transaction, which is a no-op if already committed or rolled back. | ||
if err := txCtx.doRollback(); err != nil { | ||
log.Ctx(txCtx).Error().Err(err).Msg("failed to rollback transaction on tx cleanup") | ||
} | ||
}() | ||
select { | ||
case <-innerCtx.Done(): | ||
case <-txCtx.closeCh: | ||
} |
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.
We can simplify this by extracting the logic of this deferred function to below the select statement and removing the defer statement.
// close closes the transactional context. | ||
// already called with the mutex held. | ||
func (b *txContext) close() { | ||
if !b.closed { | ||
close(b.closeCh) | ||
b.closed = true | ||
} | ||
} | ||
|
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.
since this logic should not be called without locking my preference would be to inline the logic of this function into the various places it's used and drop the function.
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.
please consider addressing remaining comments. then lgtm
Currently we auto cancel the context when the transaction is committed, which means any operation using that context can fail if it depends on the context's done state. This is causing flakiness in
TestBeginMultipleTransactions_Sequential
test in windows as the second transaction is created from the previous context, which will also be cancelled and rolled-back when the first one is committed and then cancelled.This PR fixes the issue by no longer cancelling the context of tx commit or rollback