'Setting the timeout with Knex.js for MSSQL
I use knex.js in a node environment to run a web server that makes sql calls. I have a query that takes over 30 seconds to complete, but when it's run through knex, the default timeout seems to be 15 seconds, so I get the following timeout error:
RequestError: Timeout: Request failed to complete in 15000ms
...
How do I change the timeout for mssql queries? The official doc has an example of setting timeout on a specific query with .timeout() but this feature doesn't work with mssql. I've also tried everything in this github issue without any luck. After trying all of that, I have this messy looking connection config:
const connection = require('knex')({
client: 'mssql',
connection: {
host : process.env.NODE_ENV == 'production' ? '172.18.1.66' : 'localhost',
user : secrets.user,
password : secrets.password,
database : 'EdgeView',
dialect: "mssql",
options: {
'enableArithAbort': true,
'requestTimeout': 150000,
'idleTimeoutMillis': 150000
},
pool: {
max: 10,
min: 0,
idleTimeoutMillis: 150000
},
dialectOptions:{
requestTimeout: 300000,
options: {
"requestTimeout": 300000
}
}
}
});
The error did not change, none of these timeout values seems to have had an impact. The query it's self is just a raw query:
let res = connection.raw(GETSQLSTRING(args));
Solution 1:[1]
The answer was simply this:
const connection = require('knex')({
client: 'mssql',
connection: {
host : 'edge-sql',
user : secrets.user,
password : secrets.password,
requestTimeout: 600000,
database : 'EdgeView'
}
});
Thanks to BGPHiJACK for pointing me towards better documentation.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | SpeedOfRound |
