Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Bugfix/redis health check race condition (#6504)

Thomas Kaul80057ccc73f2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 457f988841..b0bbc8bcfb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improved the language localization for Dutch (`nl`)
+### Fixed
+
+- Fixed false _Redis_ health check failures by using unique keys and increasing the timeout to 5s
+
## 2.248.0 - 2026-03-07
### Added
diff --git a/apps/api/src/app/redis-cache/redis-cache.service.ts b/apps/api/src/app/redis-cache/redis-cache.service.ts
index 1ea0a61375..619d23fc50 100644
--- a/apps/api/src/app/redis-cache/redis-cache.service.ts
+++ b/apps/api/src/app/redis-cache/redis-cache.service.ts
@@ -6,7 +6,7 @@ import { CACHE_MANAGER, Cache } from '@nestjs/cache-manager';
import { Inject, Injectable, Logger } from '@nestjs/common';
import Keyv from 'keyv';
import ms from 'ms';
-import { createHash } from 'node:crypto';
+import { createHash, randomUUID } from 'node:crypto';
@Injectable()
export class RedisCacheService {
@@ -75,13 +75,16 @@ export class RedisCacheService {
}
public async isHealthy() {
- const testKey = '__health_check__';
+ const HEALTH_CHECK_TIMEOUT = ms('5 seconds');
+
+ const testKey = `__health_check__${randomUUID().replace(/-/g, '')}`;
const testValue = Date.now().toString();
try {
await Promise.race([
(async () => {
- await this.set(testKey, testValue, ms('1 second'));
+ await this.set(testKey, testValue, HEALTH_CHECK_TIMEOUT);
+
const result = await this.get(testKey);
if (result !== testValue) {
@@ -91,7 +94,7 @@ export class RedisCacheService {
new Promise((_, reject) =>
setTimeout(
() => reject(new Error('Redis health check failed: timeout')),
- ms('2 seconds')
+ HEALTH_CHECK_TIMEOUT
)
)
]);