From 97d39b33c6a0a7a6b30c30714d800f72bf883f79 Mon Sep 17 00:00:00 2001 From: FORESTIER Fabien <fabien.forestier@soprasteria.com> Date: Mon, 24 Jun 2019 16:11:45 +0200 Subject: [PATCH] Quit the redis client in health check and timeout the client connection if longer than 2 seconds --- src/health/redis.healthIndicator.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/health/redis.healthIndicator.ts b/src/health/redis.healthIndicator.ts index 7337158..3f7293b 100644 --- a/src/health/redis.healthIndicator.ts +++ b/src/health/redis.healthIndicator.ts @@ -16,6 +16,7 @@ export class RedisHealthIndicator extends HealthIndicator { await new Promise((resolve, reject) => { client.on('ready', resolve); client.on('error', reject); + setTimeout(reject, 2000); }).catch((err) => { client.quit(); throw new HealthCheckError('Redis connection failed', { @@ -27,6 +28,8 @@ export class RedisHealthIndicator extends HealthIndicator { }); }); + client.quit(); + return this.getStatus('Redis', true); } } \ No newline at end of file -- GitLab