Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(infra): keep a stored built-in Redis that a pin switches off

Yudhi Armyndharis0ded3683814b
diff --git a/src/modules/infra/config-sections.ts b/src/modules/infra/config-sections.ts
index 9975faee7..b122ced77 100644
--- a/src/modules/infra/config-sections.ts
+++ b/src/modules/infra/config-sections.ts
@@ -173,13 +173,15 @@ export function applyRedisSection(
const redisBuiltIn = redis.builtIn ?? existing.REDIS_BUILTIN === 'true';
// What the next boot reads: a value the environment pins, else this save's, else the stored one. The queue
// section is applied first, so its switch is in `updates` already.
- if (datastoreInUse('redis', key => (isEnvPinned(key) ? process.env[key] : (updates[key] ?? existing[key])))) {
+ const saved = (key: string): string | undefined => updates[key] ?? existing[key];
+ if (datastoreInUse('redis', key => (isEnvPinned(key) ? process.env[key] : saved(key)))) {
if (redisBuiltIn) profiles.push('redis');
- } else {
- // Nothing the next boot runs reaches Redis, so no bundled container may be started for it at boot or kept by
- // the restart, which keeps a container while the saved host still names it.
+ } else if (!datastoreInUse('redis', saved)) {
+ // Nothing the next boot runs reaches Redis, and the file does not either once a pin is removed, so no
+ // bundled container may be started for it at boot or kept by the restart, which keeps a container while the
+ // saved host still names it. A Redis only a pin switches off keeps the stored choice.
updates.REDIS_BUILTIN = 'false';
- if ((updates.REDIS_HOST ?? existing.REDIS_HOST) === 'redis') staleKeys.add('REDIS_HOST');
+ if (saved('REDIS_HOST') === 'redis') staleKeys.add('REDIS_HOST');
}
}
diff --git a/src/modules/infra/infra-config.controller.spec.ts b/src/modules/infra/infra-config.controller.spec.ts
index 9b05d6214..9cafa8da7 100644
--- a/src/modules/infra/infra-config.controller.spec.ts
+++ b/src/modules/infra/infra-config.controller.spec.ts
@@ -1161,6 +1161,21 @@ describe('InfraConfigController.saveConfig built-in/external mode flips and the
expect(env).toContain('REDIS_HOST=redis');
});
+ // The stored choice is kept for the day the pin is removed: the file still uses Redis then.
+ it('keeps a stored bundled Redis while the environment pins REDIS_ENABLED off', () => {
+ process.env.REDIS_ENABLED = 'false';
+ recordPinnedEnvKeys({ REDIS_ENABLED: 'false' });
+
+ const env = written(
+ { redis: { builtIn: true, host: 'redis', port: '6379' }, queue: { enabled: false } },
+ BUILTIN_REDIS_ENV,
+ );
+
+ expect(env).toContain('REDIS_ENABLED=true');
+ expect(env).toContain('REDIS_BUILTIN=true');
+ expect(env).toContain('REDIS_HOST=redis');
+ });
+
it('asks for the redis profile only while something uses Redis', () => {
const profilesOf = (config: unknown) => {
(fs.existsSync as jest.Mock).mockReturnValue(true);