mssql 12.5.3 → 12.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/base/transaction.js +19 -2
- package/lib/tedious/request.js +12 -0
- package/lib/tedious/transaction.js +1 -0
- package/package.json +1 -1
package/lib/base/transaction.js
CHANGED
|
@@ -152,6 +152,7 @@ class Transaction extends EventEmitter {
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
this._aborted = false
|
|
155
|
+
this._abortReason = null
|
|
155
156
|
this._rollbackRequested = false
|
|
156
157
|
if (isolationLevel) {
|
|
157
158
|
if (Object.keys(ISOLATION_LEVEL).some(key => {
|
|
@@ -199,6 +200,22 @@ class Transaction extends EventEmitter {
|
|
|
199
200
|
})
|
|
200
201
|
}
|
|
201
202
|
|
|
203
|
+
/**
|
|
204
|
+
* Creates a TransactionError for an aborted transaction, preserving the
|
|
205
|
+
* original abort reason (if any) as `originalError`.
|
|
206
|
+
*
|
|
207
|
+
* @private
|
|
208
|
+
* @return {TransactionError}
|
|
209
|
+
*/
|
|
210
|
+
|
|
211
|
+
_createAbortError () {
|
|
212
|
+
const err = new TransactionError('Transaction has been aborted.', 'EABORT')
|
|
213
|
+
if (this._abortReason) {
|
|
214
|
+
Object.defineProperty(err, 'originalError', { enumerable: true, value: this._abortReason })
|
|
215
|
+
}
|
|
216
|
+
return err
|
|
217
|
+
}
|
|
218
|
+
|
|
202
219
|
/**
|
|
203
220
|
* @private
|
|
204
221
|
* @param {basicCallback} [callback]
|
|
@@ -207,7 +224,7 @@ class Transaction extends EventEmitter {
|
|
|
207
224
|
|
|
208
225
|
_commit (callback) {
|
|
209
226
|
if (this._aborted) {
|
|
210
|
-
return setImmediate(callback,
|
|
227
|
+
return setImmediate(callback, this._createAbortError())
|
|
211
228
|
}
|
|
212
229
|
|
|
213
230
|
if (!this._acquiredConnection) {
|
|
@@ -279,7 +296,7 @@ class Transaction extends EventEmitter {
|
|
|
279
296
|
|
|
280
297
|
_rollback (callback) {
|
|
281
298
|
if (this._aborted) {
|
|
282
|
-
return setImmediate(callback,
|
|
299
|
+
return setImmediate(callback, this._createAbortError())
|
|
283
300
|
}
|
|
284
301
|
|
|
285
302
|
if (!this._acquiredConnection) {
|
package/lib/tedious/request.js
CHANGED
|
@@ -300,6 +300,10 @@ class Request extends BaseRequest {
|
|
|
300
300
|
} catch (e) {
|
|
301
301
|
// noop
|
|
302
302
|
}
|
|
303
|
+
if (this.parent._aborted) {
|
|
304
|
+
const reason = err || errors[errors.length - 1]
|
|
305
|
+
if (reason) this.parent._abortReason = reason
|
|
306
|
+
}
|
|
303
307
|
callback(err, ...args)
|
|
304
308
|
}
|
|
305
309
|
if (err) return callbackWithRelease(err)
|
|
@@ -501,6 +505,10 @@ class Request extends BaseRequest {
|
|
|
501
505
|
}
|
|
502
506
|
|
|
503
507
|
this.parent.release(connection)
|
|
508
|
+
if (this.parent._aborted) {
|
|
509
|
+
const reason = error || errors[errors.length - 1]
|
|
510
|
+
if (reason) this.parent._abortReason = reason
|
|
511
|
+
}
|
|
504
512
|
hasReturned = true
|
|
505
513
|
|
|
506
514
|
if (error) {
|
|
@@ -865,6 +873,10 @@ class Request extends BaseRequest {
|
|
|
865
873
|
}
|
|
866
874
|
|
|
867
875
|
this.parent.release(connection)
|
|
876
|
+
if (this.parent._aborted) {
|
|
877
|
+
const reason = error || errors[errors.length - 1]
|
|
878
|
+
if (reason) this.parent._abortReason = reason
|
|
879
|
+
}
|
|
868
880
|
hasReturned = true
|
|
869
881
|
|
|
870
882
|
if (error) {
|
|
@@ -23,6 +23,7 @@ class Transaction extends BaseTransaction {
|
|
|
23
23
|
this._acquiredConnection = null
|
|
24
24
|
this._acquiredConfig = null
|
|
25
25
|
this._aborted = true
|
|
26
|
+
this._abortReason = this._abortReason || new Error('Transaction was rolled back by the server')
|
|
26
27
|
|
|
27
28
|
publish(CHANNELS.TRANSACTION_ROLLBACK, () => ({
|
|
28
29
|
transactionId: IDS.get(this),
|