From c5c2222b8c3e9f0af51327797f1f9d74a9b94090 Mon Sep 17 00:00:00 2001 From: softsimon Date: Sat, 30 Jan 2021 19:20:52 +0700 Subject: [PATCH] Increased database query timeouts fixes #315 --- backend/src/api/statistics.ts | 15 ++++++++------- backend/src/database.ts | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/backend/src/api/statistics.ts b/backend/src/api/statistics.ts index 619331b77..f98917231 100644 --- a/backend/src/api/statistics.ts +++ b/backend/src/api/statistics.ts @@ -7,6 +7,7 @@ import { Statistic, TransactionExtended, OptimizedStatistic } from '../mempool.i class Statistics { protected intervalTimer: NodeJS.Timer | undefined; protected newStatisticsEntryCallback: ((stats: OptimizedStatistic) => void) | undefined; + protected queryTimeout = 120000; public setNewStatisticsEntryCallback(fn: (stats: OptimizedStatistic) => void) { this.newStatisticsEntryCallback = fn; @@ -300,7 +301,7 @@ class Statistics { try { const connection = await DB.pool.getConnection(); const query = `SELECT * FROM statistics ORDER BY id DESC LIMIT 120`; - const [rows] = await connection.query(query); + const [rows] = await connection.query({ sql: query, timeout: this.queryTimeout }); connection.release(); return this.mapStatisticToOptimizedStatistic(rows); } catch (e) { @@ -313,7 +314,7 @@ class Statistics { try { const connection = await DB.pool.getConnection(); const query = this.getQueryForDays(180); - const [rows] = await connection.query(query); + const [rows] = await connection.query({ sql: query, timeout: this.queryTimeout }); connection.release(); return this.mapStatisticToOptimizedStatistic(rows); } catch (e) { @@ -326,7 +327,7 @@ class Statistics { try { const connection = await DB.pool.getConnection(); const query = this.getQueryForDays(1260); - const [rows] = await connection.query(query); + const [rows] = await connection.query({ sql: query, timeout: this.queryTimeout }); connection.release(); return this.mapStatisticToOptimizedStatistic(rows); } catch (e) { @@ -339,7 +340,7 @@ class Statistics { try { const connection = await DB.pool.getConnection(); const query = this.getQueryForDays(5040); - const [rows] = await connection.query(query); + const [rows] = await connection.query({ sql: query, timeout: this.queryTimeout }); connection.release(); return this.mapStatisticToOptimizedStatistic(rows); } catch (e) { @@ -352,7 +353,7 @@ class Statistics { try { const connection = await DB.pool.getConnection(); const query = this.getQueryForDays(15120); - const [rows] = await connection.query(query); + const [rows] = await connection.query({ sql: query, timeout: this.queryTimeout }); connection.release(); return this.mapStatisticToOptimizedStatistic(rows); } catch (e) { @@ -365,7 +366,7 @@ class Statistics { try { const connection = await DB.pool.getConnection(); const query = this.getQueryForDays(30240); - const [rows] = await connection.query(query); + const [rows] = await connection.query({ sql: query, timeout: this.queryTimeout }); connection.release(); return this.mapStatisticToOptimizedStatistic(rows); } catch (e) { @@ -378,7 +379,7 @@ class Statistics { try { const connection = await DB.pool.getConnection(); const query = this.getQueryForDays(60480); - const [rows] = await connection.query(query); + const [rows] = await connection.query({ sql: query, timeout: this.queryTimeout }); connection.release(); return this.mapStatisticToOptimizedStatistic(rows); } catch (e) { diff --git a/backend/src/database.ts b/backend/src/database.ts index f288fcfa3..571fab074 100644 --- a/backend/src/database.ts +++ b/backend/src/database.ts @@ -11,6 +11,7 @@ export class DB { password: config.DATABASE.PASSWORD, connectionLimit: 10, supportBigNumbers: true, + acquireTimeout: 60000, }); }