Issue
I have an operation to execute at night
@Cron(CronExpression.EVERY_DAY_AT_1AM)
async setValideFileRemainder() {
var date = new Date();
let dateToday = date.toISOString().split('T')[0];
let remainders = await this.healthFileRepository.find({
where: { remainder_date: dateToday }})
for (let file of remainders) {
file.is_valide = 1;
await this.healthFileRepository.save(file);
}
}
when I test this function in an endpoint or each 5 min for example it works, but at night it always gives me this error:
[Nest] 18728 - 09/15/2021, 7:53:52 AM [Scheduler] QueryFailedError: read ECONNRESET +38765424ms
PS: I'm using MySQL as a database
Solution
I suspect you are running into a MySQL connection timeout as your client application is idling. The MySQL server will disconnect your client if there is no activity within the time range configured by wait_timeout
.
You will either need to:
- tweak your MySQL server configuration and increase
wait_timeout
- send keep alive queries to your server (eg.
SELECT 1
) in an interval shorter thanwait_timeout
- handle connection drops gracefully, as they can occur for more reasons that are beyond your application or the SQL server (eg. route drops, link down, packet loss, ...)
Answered By - JimmyBlu