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

driver-adapters: close tx on drop #4286

Merged
merged 6 commits into from
Sep 27, 2023
Merged

driver-adapters: close tx on drop #4286

merged 6 commits into from
Sep 27, 2023

Conversation

aqrln
Copy link
Member

@aqrln aqrln commented Sep 26, 2023

Fixes transactions not being closed after some errors on the Rust side:

  • errors that happen in <JsQueryable as TransactionCapable>::start_transaction
  • caught and unwound panics
  • maybe more

It is one of the two reasons that may trigger nested transaction errors with libSQL.

It is also a prerequisite for #4288 (otherwise those errors can leave the libSQL connection in locked state).

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 26, 2023

CodSpeed Performance Report

Merging #4286 will not alter performance

Comparing libsql-tx (9437aff) with main (4bf3cce)

Summary

✅ 11 untouched benchmarks

@janpio janpio added the topic: driver adapters formerly phase 1 label Sep 26, 2023
@@ -96,6 +96,13 @@ export interface Transaction extends Queryable {
* Rolls back the transaction.
*/
rollback(): Promise<Result<void>>
/**
* Discards and closes the transaction which may or may not have been committed or rolled back.
* This operation must be synchronous. If the implementation requires calling creating new
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if requiring a synchronous function is the best approach, perhaps it would be better to let it be async, and either add a method to AsyncJsFunction that allows calling it in the background ignoring the result, or spawn a new tokio task in JsTransaction::drop that will actually await it and maybe log an error if it happens.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Close trait's close is not async, so we might want to keep this synchronous for convenience, unless we measure that it can compromise throughput.

Copy link
Member Author

@aqrln aqrln Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not even about throughput, we'll have to do exactly the same amount of work synchronously until the first yield point in async function or end of sync function regardless of what we choose. The implementation of this method for Turso and PlanetScale is only "synchronous" in that it doesn't return a Promise and spawns a task on the event loop without waiting for it, and the implementation for pg and Neon would still only use synchronous operations even if the method was marked as async.

So changing this to be async should not really affect the performance or improve throughput but might arguably be a little cleaner, and might be a little more convenient when implementing new driver adapters (it will be harder to accidentally end up with unhandled promise rejections there).

Not something that we must decide right now, of course, we can improve this later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation. makes sense.

Copy link
Contributor

@miguelff miguelff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed some of the review feedback as changes in the PR.

@@ -96,6 +96,13 @@ export interface Transaction extends Queryable {
* Rolls back the transaction.
*/
rollback(): Promise<Result<void>>
/**
* Discards and closes the transaction which may or may not have been committed or rolled back.
* This operation must be synchronous. If the implementation requires calling creating new
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Close trait's close is not async, so we might want to keep this synchronous for convenience, unless we measure that it can compromise throughput.

@aqrln aqrln marked this pull request as ready for review September 27, 2023 13:14
@aqrln aqrln requested a review from a team as a code owner September 27, 2023 13:14
@aqrln aqrln added this to the 5.4.0 milestone Sep 27, 2023
@aqrln aqrln merged commit 4dbb252 into main Sep 27, 2023
27 of 35 checks passed
@aqrln aqrln deleted the libsql-tx branch September 27, 2023 14:02
aqrln added a commit that referenced this pull request Nov 21, 2023
Remove the boilerplate `Transaction.dispose` method from the public
driver adapter interface and move the corresponding functionality
directly to the destructor of `TransactionProxy`.

Refs: #4286
Closes: prisma/team-orm#391
aqrln added a commit that referenced this pull request Nov 21, 2023
Remove the boilerplate `Transaction.dispose` method from the public
driver adapter interface and move the corresponding functionality
directly to the destructor of `TransactionProxy`.

Refs: #4286
Closes: prisma/team-orm#391
aqrln added a commit that referenced this pull request Nov 23, 2023
Remove the boilerplate `Transaction.dispose` method from the public
driver adapter interface and move the corresponding functionality
directly to the destructor of `TransactionProxy`.

Refs: #4286
Closes: prisma/team-orm#391
aqrln added a commit that referenced this pull request Nov 24, 2023
Remove the boilerplate `Transaction.dispose` method from the public
driver adapter interface and move the corresponding functionality
directly to the destructor of `TransactionProxy`.

Refs: #4286
Closes: prisma/team-orm#391
aqrln added a commit that referenced this pull request Nov 27, 2023
…4489)

Remove the boilerplate `Transaction.dispose` method from the public
driver adapter interface and move the corresponding functionality
directly to the destructor of `TransactionProxy`.

Refs: #4286
Closes: prisma/team-orm#391
Co-authored-by: Miguel Fernández <fernandez@prisma.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: driver adapters formerly phase 1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants