-
Notifications
You must be signed in to change notification settings - Fork 475
Closed
Description
We're running a next.js application on a Windows Server using iisnode.
Everything works fine, but during every ~50th user session we experience: RequestError: Timeout: Request failed to complete in 15000ms. It's enough to be a hassle but not enough to be able to be reproduced.
Is there anything conceptually wrong with the way we're using a global connection pool? (Simplified code below)
Or is this kind of "once in a while" timeout problems common when using mssql with pools?
helpers.js
import mssql from 'mssql'
const sqlConfig = {
...
pool: {
max: 10,
min: 0,
idleTimeoutMillis: 10000,
},
options: {
trustServerCertificate: true,
},
};
const mainSqlPool = new mssql.ConnectionPool(sqlConfig);
let sqlPool = null;
async function getSqlPool() {
if (!sqlPool) {
try {
const tempPool = await mainSqlPool.connect();
sqlPool = tempPool;
} catch (err) {
console.error('Failed to connect to SQL pool:', err);
throw err;
}
}
return sqlPool;
}
mainSqlPool.on('error', (err) => {
console.error('SQL pool error', err);
sqlPool = null;
});
export async function runQuery(query) {
try {
const pool = getSqlPool()
const request = new mssql.Request(pool);
const result = await request.query(query);
return result;
} catch (err) {
console.error('err', err);
throw err;
}
}api/createUser.js
export default handler = (req, res) => {
return await runQuery("insert into UserTable (name) values ('John Doe')")
}Metadata
Metadata
Assignees
Labels
No labels