Error: Timeout: Request failed to complete in 15000ms
Problem : When I hit the end point I am getting timeout error when it tries to get data from MSSQL. This happens when query execution is more that 15s.
DB Connection request timeout is reverting to default of 15s even when I override it via config requestTimeout options.
Below is the code in App Module
@Module({
imports: [
TypeOrmModule.forFeature([TestEntity]),
TestModule1,
ConfigModule2,
TestModule3,
TestModule4,
DatabaseModule,
TypeOrmModule.forRootAsync({
imports: [ConfigModule2],
useFactory: (config: ConfigService): Promise<TypeOrmModuleOptions> => {
return DatabaseConnectionHelper.getConnection(
config,
Test,
DatabaseConnectionHelper.connectionKey,
[TestEntity],
);
},
inject: [ConfigService],
}),
],
controllers: [AppController],
providers: [AppService, TestEntity, RepoClass],
})
export class AppModule {}
-------------------------------
App Module gets the connection value from static method as below,
static getConnection(
config: ConfigService,
applicationOwner: ApplicationOwner,
ConnectionKey: string,
entities: any[],
): Promise<TypeOrmModuleOptions> {
return config
.getValue(
applicationOwner.toUpperCase(),
'UAT',
ConnectionKey,
)
.then(connectionString => {
const connection = DatabaseConnectionHelper.getConnectionFromString(
connectionString,
);
return {
type: 'mssql',
host: sql0000,--e.g.
port: 0000,--e.g.
username: connection.username,
password: connection.password,
database: connection.database,
**requestTimeout: 300000,
options: { requestTimeout: 300000, encrypt: true },**
entities: entities,
synchronize: false,
} as TypeOrmModuleOptions;
});
}
Then via Repository class it calls the StoreProcedure to get data as below
const res = this.TestRepositoryClass<Entity>.query(sqlquery);
Getting error when query takes more than 15s even if I set requestTimeout more the 15s
[Nest] 25576 - 04/10/2022, 16:47:08 Error: Timeout: Request failed to complete in 15000ms +17427ms QueryFailedError: Error: Timeout: Request failed to complete in 15000ms at new QueryFailedError (.....\node_modules\typeorm\error\QueryFailedError.js:11:28) at .....\node_modules\typeorm\driver\sqlserver\SqlServerQueryRunner.js:301:61 at .....\node_modules\mssql\lib\base\request.js:414:25 at Request.userCallback (.....\node_modules\mssql\lib\tedious\request.js:479:15) at Request.callback (.....\node_modules\mssql\node_modules\tedious\lib\request.js:56:14) at Connection.message (.....\node_modules\mssql\node_modules\tedious\lib\connection.js:2449:24) at Connection.dispatchEvent (.....\node_modules\mssql\node_modules\tedious\lib\connection.js:1279:15) at MessageIO.<anonymous> (.....\node_modules\mssql\node_modules\tedious\lib\connection.js:1139:14) at MessageIO.emit (events.js:315:20) at Message.<anonymous> (.....\node_modules\mssql\node_modules\tedious\lib\message-io.js:46:14)
Node - v 14.15.5 mssql - "_from": "mssql@^6.2.0", "_id": "[email protected]", tedious - "_from": "tedious@^6.7.1", "_id": "[email protected]",
Hi, @komtalekar , Thanks for raising this. From your comment, I saw that you are mentioned version 6.7.1, which is a pretty old version of tedious. Could you double check whether this is the version that you on? Is it possible for you to try a later version of our driver? The latest should be 15.1. Also, which version of SQL server are you trying to connect to? By the way, have you tried to use tedious by it self without mssql? if possible, this may help us isolated the issues a bit further. Also, we actually considering improve our timeout handling. It has some issue within it. There actually a request level API that can also modified the time out settings: request.setTimeout(timeout). If you want, you can also try this, see if it helps.
We are seeing similar issue with version 15.1....we are using this package with adonisjs. Is there a easy way to use request.setTimeout(timeout) with adonisjs ?
I'm planning to replace the request.setTimeout functionality with support for AbortSignal instead. That should give users a much more granular behaviour for when and how requests time out.
Regarding AdonisJS, I've never used that before and don't know if they plan to expose similar behaviour.
One other option you have is to set the connection level request timeout value to a higher value. But you need to keep in mind this will increase the timeout for all requests you are doing.