Expected Behavior
Request timeouts mean requests time out and connections on which the request timeout happened are added back to the connection pool, ready to be used again in the future
Current Behavior
Request timeout settings are being ignored
These are my 4 files containing the test code. A few strings you'll have to substitute before running:
<YOUR_SLOW_SQL_STATEMENT_HERE>
<YOUR_DB_USER_NAME_HERE>
<YOUR_DB_USER_PASSWORD_HERE>
<YOUR_SERVER_IP_HERE>
<YOUR_DB_PORT_HERE>
'<YOUR_DB_NAME_HERE>'
then run by invoking 'node app.js'
my CPU usage spikes like crazy after connection.execSql(sqlRequest) is called.... :/
I've been playing around with some of the timeout settings and I think they are just being ignored. For example, request timeout is set to 5000 millis, it does not timeout after 5 seconds, it just keep going... connection is not being released back to the pool... am I doing something wrong? Maybe there is some config on the SQL server I need to check?
Steps to Reproduce (for bugs)
package.json
{
"name": "tedconpooltester",
"version": "1.0.0",
"description": "tedious connection pool tester",
"main": "app.js",
"private": true,
"dependencies": {
"tedious": "1.15.0",
"tedious-connection-pool": "^1.0.5"
},
"author": "me",
"license": "ISC"
}
app.js
const sqlRunner = require('./sqlrunner')
console.log('Tedious connection pool tester running...')
function intervalFunc() {
sqlRunner.runSql()
.then(result => {
console.log(result)
})
.catch(err => {
console.log(err)
})
}
// setInterval(intervalFunc, 30000);
intervalFunc()
sqlrunner.js
const connectionPool = require('./sqlserverConnectionPool')
const MssqlRequest = require('tedious').Request
module.exports = {
runSql: function () {
return new Promise((resolve, reject) => {
console.log('pool status ' + connectionPool.connections.map(x => x.status))
connectionPool.acquire(function (err, connection) {
console.log('acquiring sqlserver connection...')
if (err) {
console.log(err)
reject(err)
return
}
console.log('connection acquired')
let sqlRequest = new MssqlRequest('<YOUR_SLOW_SQL_STATEMENT_HERE>', function (err, rowCount, rows) {
console.log('releasing connection ' + connection)
connection.release()
if (err) {
console.log('Error retrieving SQL data ' + err)
reject(err)
} else if (rowCount === 0) {
console.log('0 rows returned')
resolve(0)
} else {
console.log(rowCount + ' rows returned')
resolve(rowCount)
}
})
console.log('executing sql statement')
connection.execSql(sqlRequest)
})
})
}
}
sqlserverConnectionPool.js
const ConnectionPool = require('tedious-connection-pool')
const poolConfig = {
min: 1, // 5
max: 1, // 15
idleTimeout: 10000,
acquireTimeout: 12000,
log: false
}
const config = {
userName: '<YOUR_DB_USER_NAME_HERE>',
password: '<YOUR_DB_USER_PASSWORD_HERE>',
server: '<YOUR_SERVER_IP_HERE>',
options: {
port: <YOUR_DB_PORT_HERE>,
database: '<YOUR_DB_NAME_HERE>'
trustedConnection: true,
rowCollectionOnRequestCompletion: true,
useUTC: false,
readOnlyIntent: true,
connectTimeout: 15000,
requestTimeout: 5000,
cancelTimeout: 3000,
maxRetriesOnTransientErrors: 0
}
}
const pool = new ConnectionPool(poolConfig, config)
pool.on('error', function (err) {
console.log('db connection pool error - ' + err + ' pool size ' + pool.connections.length')
})
module.exports = pool
Reason For Request (for feature requests)
Possible Solution
Background Details
Environment
- Node.js Version: 8.13.0
- Windows/Mac/Linux: Mac OS X 10.14.4
Expected Behavior
Request timeouts mean requests time out and connections on which the request timeout happened are added back to the connection pool, ready to be used again in the future
Current Behavior
Request timeout settings are being ignored
These are my 4 files containing the test code. A few strings you'll have to substitute before running:
<YOUR_SLOW_SQL_STATEMENT_HERE>
<YOUR_DB_USER_NAME_HERE>
<YOUR_DB_USER_PASSWORD_HERE>
<YOUR_SERVER_IP_HERE>
<YOUR_DB_PORT_HERE>
'<YOUR_DB_NAME_HERE>'
then run by invoking 'node app.js'
my CPU usage spikes like crazy after connection.execSql(sqlRequest) is called.... :/
I've been playing around with some of the timeout settings and I think they are just being ignored. For example, request timeout is set to 5000 millis, it does not timeout after 5 seconds, it just keep going... connection is not being released back to the pool... am I doing something wrong? Maybe there is some config on the SQL server I need to check?
Steps to Reproduce (for bugs)
package.json
app.js
sqlrunner.js
sqlserverConnectionPool.js
Reason For Request (for feature requests)
Possible Solution
Background Details
Environment