LibreChat/packages/api/src/cache
Danny Avila 56281ece30
🚰 ci: Close Leaked Redis Clients in Cache Integration Tests (#13649)
* 🧹 fix: Close Leaked Redis Clients in Cache Integration Tests

Importing `redisClients` constructs and connects BOTH `ioredisClient`
and `keyvRedisClient` as module side effects, but most cache/mcp
integration specs disconnected at most one of them — and specs that
re-import the module per test via `jest.resetModules()` leaked a fresh
pair of connected clients (sockets + ping timers) for every test.

On runners where jest resolves to a single worker (2-core machines with
`maxWorkers: '50%'`), the suite runs in-band and the leaked handles keep
the main process alive after all tests pass — the run hangs until the
CI job timeout. On larger runners jest recovers only by force-exiting
the leaked worker ("A worker process has failed to exit gracefully...").

- add a `closeRedisClients()` test helper that settles the connect
  promise and closes both clients of a `redisClients` module instance
- call it from every cache/mcp integration spec that creates clients,
  mirroring what LeaderElection.cache_integration.spec.ts already does
- remove the rethrow in the `keyvRedisClientReady.catch(...)` logging
  handler — rethrowing inside `.catch` creates a new, never-observed
  rejected promise, turning any failed initial connect into a
  guaranteed unhandled rejection; callers awaiting
  `keyvRedisClientReady` still observe the original rejection

All four `test:cache-integration` stages now pass AND exit cleanly with
`--maxWorkers=1` against both single-node and cluster Redis, with no
force-exit warning in worker mode.

* 🧹 chore: Treat testRedisOperations as Assertion in expect-expect Rule

* 🗂️ chore: Sort Imports per Repo Convention
2026-06-10 08:59:13 -04:00
..
__tests__ 🚰 ci: Close Leaked Redis Clients in Cache Integration Tests (#13649) 2026-06-10 08:59:13 -04:00
cacheConfig.ts ️ refactor: Migrate @librechat/api build to tsdown (#13595) 2026-06-08 10:54:48 -04:00
cacheFactory.ts 🧊 fix: In-Memory Endpoint Token Config Cache Isolation (#12673) 2026-04-15 09:41:42 -04:00
index.ts 📡 refactor: MCP Runtime Config Sync with Redis Distributed Locking (#10352) 2025-12-11 16:36:15 -05:00
keyvFiles.ts ️ refactor: Migrate @librechat/api build to tsdown (#13595) 2026-06-08 10:54:48 -04:00
keyvMongo.ts ️ refactor: Migrate @librechat/api build to tsdown (#13595) 2026-06-08 10:54:48 -04:00
redisClients.ts 🚰 ci: Close Leaked Redis Clients in Cache Integration Tests (#13649) 2026-06-10 08:59:13 -04:00
redisUtils.ts 🧩 fix: Add REDIS_CLUSTER_SAFE_DELETE Flag for ElastiCache Serverless CROSSSLOT Errors (#13275) 2026-05-24 14:49:40 -04:00