mssql 12.7.7 → 12.7.8

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/README.md CHANGED
@@ -934,6 +934,7 @@ __Errors__
934
934
  - ENOTOPEN (`ConnectionError`) - Connection not yet open.
935
935
  - ECONNCLOSED (`ConnectionError`) - Connection is closed.
936
936
  - ENOTBEGUN (`TransactionError`) - Transaction has not begun.
937
+ - EREQINPROG (`TransactionError`) - Can't acquire connection for the request. There is another request in progress.
937
938
  - EABORT (`TransactionError`) - Transaction was aborted (by user or because of an error).
938
939
 
939
940
  ---------------------------------------
@@ -1157,6 +1158,7 @@ __Errors__
1157
1158
  - ENOTOPEN (`ConnectionError`) - Connection not yet open.
1158
1159
  - ECONNCLOSED (`ConnectionError`) - Connection is closed.
1159
1160
  - ENOTBEGUN (`TransactionError`) - Transaction has not begun.
1161
+ - EREQINPROG (`TransactionError`) - Can't acquire connection for the request. There is another request in progress.
1160
1162
  - EABORT (`TransactionError`) - Transaction was aborted (by user or because of an error).
1161
1163
  - EINJECT (`RequestError`) - Parameter type is not a valid identifier. See [Identifiers](#identifiers).
1162
1164
 
@@ -1204,6 +1206,7 @@ __Errors__
1204
1206
  - ENOTOPEN (`ConnectionError`) - Connection not yet open.
1205
1207
  - ECONNCLOSED (`ConnectionError`) - Connection is closed.
1206
1208
  - ENOTBEGUN (`TransactionError`) - Transaction has not begun.
1209
+ - EREQINPROG (`TransactionError`) - Can't acquire connection for the request. There is another request in progress.
1207
1210
  - EABORT (`TransactionError`) - Transaction was aborted (by user or because of an error).
1208
1211
  - EINJECT (`RequestError`) - Parameter type is not a valid identifier. See [Identifiers](#identifiers).
1209
1212
 
@@ -1251,6 +1254,7 @@ __Errors__
1251
1254
  - ENOTOPEN (`ConnectionError`) - Connection not yet open.
1252
1255
  - ECONNCLOSED (`ConnectionError`) - Connection is closed.
1253
1256
  - ENOTBEGUN (`TransactionError`) - Transaction has not begun.
1257
+ - EREQINPROG (`TransactionError`) - Can't acquire connection for the request. There is another request in progress.
1254
1258
  - EABORT (`TransactionError`) - Transaction was aborted (by user or because of an error).
1255
1259
  - EINJECT (`RequestError`) - Column name or parameter type is not a valid identifier. See [Identifiers](#identifiers).
1256
1260
 
@@ -2215,7 +2219,7 @@ Name | Code | Message
2215
2219
  `ConnectionError` | ECONNCLOSED | Connection is closed.
2216
2220
  `TransactionError` | ENOTBEGUN | Transaction has not begun.
2217
2221
  `TransactionError` | EALREADYBEGUN | Transaction has already begun.
2218
- `TransactionError` | EREQINPROG | Can't commit/rollback transaction. There is a request in progress.
2222
+ `TransactionError` | EREQINPROG | Can't commit/rollback transaction or acquire connection for the request. There is a request in progress.
2219
2223
  `TransactionError` | EABORT | Transaction has been aborted.
2220
2224
  `RequestError` | EREQUEST | Message from SQL Server. Error object contains additional details.
2221
2225
  `RequestError` | ECANCEL | Cancelled.
@@ -401,7 +401,13 @@ class ConnectionPool extends EventEmitter {
401
401
  }))
402
402
 
403
403
  if (typeof callback === 'function') {
404
- acquirePromise.then(connection => callback(null, connection, this.config)).catch(callback)
404
+ // called back outside the promise chain, so that what the callback throws is not taken
405
+ // for a failure to acquire and passed back to it, but reaches the process as it would
406
+ // from any other callback
407
+ acquirePromise.then(
408
+ connection => process.nextTick(callback, null, connection, this.config),
409
+ err => process.nextTick(callback, err)
410
+ )
405
411
  return this
406
412
  }
407
413
 
@@ -255,6 +255,16 @@ class Request extends BaseRequest {
255
255
  }
256
256
  }
257
257
 
258
+ // msnodesqlv8 throws, rather than calls back, for a query on a connection it has
259
+ // closed, so what it throws is handed to `done` as well, which releases the connection
260
+ const attempt = run => {
261
+ try {
262
+ run()
263
+ } catch (e) {
264
+ done(e)
265
+ }
266
+ }
267
+
258
268
  const go = () => {
259
269
  const tm = connection.tableMgr()
260
270
  // the table manager reports a failed lookup as (null, err), not error first
@@ -317,13 +327,15 @@ class Request extends BaseRequest {
317
327
  return done(e)
318
328
  }
319
329
 
320
- return connection.queryRaw(statement, function (err) {
330
+ return attempt(() => connection.queryRaw(statement, function (err) {
321
331
  if (err) { return done(err) }
322
- go()
323
- })
332
+ attempt(go)
333
+ }))
324
334
  } else {
325
- go()
335
+ attempt(go)
326
336
  }
337
+ } else {
338
+ callback(err)
327
339
  }
328
340
  })
329
341
  })
@@ -532,10 +544,19 @@ class Request extends BaseRequest {
532
544
 
533
545
  debug('request(%d): query', IDS.get(this), command)
534
546
 
535
- const req = connection.queryRaw({
536
- query_str: command,
537
- query_timeout: (this.overrides.requestTimeout ?? config.requestTimeout) / 1000 // msnodesqlv8 timeouts are in seconds (<1 second not supported)
538
- }, params)
547
+ // msnodesqlv8 throws, rather than calls back, for a query on a connection it has closed
548
+ let req
549
+ try {
550
+ req = connection.queryRaw({
551
+ query_str: command,
552
+ query_timeout: (this.overrides.requestTimeout ?? config.requestTimeout) / 1000 // msnodesqlv8 timeouts are in seconds (<1 second not supported)
553
+ }, params)
554
+ } catch (e) {
555
+ this.parent.release(connection)
556
+ const err = new RequestError(e, 'EREQUEST')
557
+ err.code = 'EREQUEST'
558
+ return callback(err)
559
+ }
539
560
 
540
561
  this._setCurrentRequest(req)
541
562
 
@@ -65,8 +65,8 @@ class Transaction extends BaseTransaction {
65
65
  this._acquiredConfig = null
66
66
 
67
67
  // deferred so that tedious is done with the connection before it is closed, and so
68
- // that the callback runs outside the pool's promise chain, which would pass anything
69
- // the callback throws back to the acquire callback above as a second error
68
+ // that what the callback throws when tedious calls back at once is not caught below
69
+ // as though tedious had thrown it
70
70
  setImmediate(() => {
71
71
  if (discard) connection.close()
72
72
  this.parent.release(connection)
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "azure",
22
22
  "node-mssql"
23
23
  ],
24
- "version": "12.7.7",
24
+ "version": "12.7.8",
25
25
  "main": "index.js",
26
26
  "type": "commonjs",
27
27
  "repository": {