- Notifications
You must be signed in to change notification settings - Fork 182
Fix operations on ended transactions #230
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
Changes from all commits
1cd5348
c0ca091
6ebdf94
9de4d92
adc7d2e
e744cdd
1361460
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
| @@ -5,6 +5,8 @@ | |
| ||
'use strict'; | ||
var debug = require('debug')('loopback:connector:postgresql:transaction'); | ||
var uuid = require('uuid'); | ||
var Transaction = require('loopback-connector').Transaction; | ||
| ||
module.exports = mixinTransaction; | ||
| ||
| @@ -18,14 +20,18 @@ function mixinTransaction(PostgreSQL) { | |
* @param cb | ||
*/ | ||
PostgreSQL.prototype.beginTransaction = function(isolationLevel, cb) { | ||
var connector = this; | ||
debug('Begin a transaction with isolation level: %s', isolationLevel); | ||
this.pg.connect(function(err, connection, done) { | ||
if (err) return cb(err); | ||
connection.autorelease = done; | ||
connection.query('BEGIN TRANSACTION ISOLATION LEVEL ' + isolationLevel, | ||
function(err) { | ||
if (err) return cb(err); | ||
cb(null, connection); | ||
var tx = new Transaction(connector, connection); | ||
tx.txId = uuid.v1(); | ||
connection.txId = tx.txId; | ||
cb(null, tx); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zbarbuto after I fixed 1) transactions bulk should work with bulk transactions: Error: read ECONNRESET at exports._errnoException (util.js:907:11) at TCP.onread (net.js:558:26) I suspect it's because here we callback the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is the case, as if you look at https://github.com/strongloop/loopback-connector/blob/master/lib/transaction.js#L48 And moreover, if you debug the code at line 76, you can see that the connection that is passed in to Calling back with transaction instead of the connection should make essentially no difference, as https://github.com/strongloop/loopback-connector/blob/master/lib/transaction.js#L88 I simply skip this step so we can attach the id to both the connection and the transaction. | ||
}); | ||
}); | ||
}; | ||
| @@ -65,6 +71,7 @@ function mixinTransaction(PostgreSQL) { | |
| ||
PostgreSQL.prototype.releaseConnection = function(connection, err) { | ||
if (typeof connection.autorelease === 'function') { | ||
connection.txId = null; | ||
connection.autorelease(err); | ||
connection.autorelease = null; | ||
} else { | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
I think here we should callback
connection
instead oftx
?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.
The goal here is to make the new connection and transaction and say "this connection is currently working on this transaction" allowing for the error if you pass in a transaction with a connection id that doesn't match.
If you callback with connection, loop back connector will make a transaction out of it and pas it up the chain. This means you how no tie between the id of the connection and the current transaction.