From 8027f3429377ae8079d763ac3adab7812924c1a3 Mon Sep 17 00:00:00 2001 From: Scott Twiname Date: Mon, 2 Dec 2024 15:34:52 +1300 Subject: [PATCH] Fix interval with 0 time causing high CPU (#2614) * Fix interval with 0 time causing high CPU * Update changelog * Update fallback check --- packages/query/CHANGELOG.md | 2 ++ packages/query/src/graphql/graphql.module.ts | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/query/CHANGELOG.md b/packages/query/CHANGELOG.md index b167eda124..558eb1ad94 100644 --- a/packages/query/CHANGELOG.md +++ b/packages/query/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- High CPU usage caused by interval with 0ms (#2614) ## [2.17.1] - 2024-11-28 ### Fixed diff --git a/packages/query/src/graphql/graphql.module.ts b/packages/query/src/graphql/graphql.module.ts index 53023f8629..6b47e021de 100644 --- a/packages/query/src/graphql/graphql.module.ts +++ b/packages/query/src/graphql/graphql.module.ts @@ -118,6 +118,8 @@ export class GraphqlModule implements OnModuleInit, OnModuleDestroy { } private setupKeepAlive(pgClient: PoolClient) { + const interval = argv['sl-keep-alive-interval'] || 180000; + logger.info(`Setup PG Pool keep alive. interval ${interval} ms`); setInterval(() => { void (async () => { try { @@ -126,7 +128,7 @@ export class GraphqlModule implements OnModuleInit, OnModuleDestroy { getLogger('db').error('Schema listener client keep-alive query failed: ', err); } })(); - }, this.config.get('sl-keep-alive-interval')); + }, interval); } private async createServer() {