Repository navigation
fix(locking,locking-redis): close the Redis client on shutdown - #17460
Conversation
ðĶ Changeset detectedLatest commit: cf56333 The changes in this PR will be included in the next version bump. This PR includes changesets to release 83 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks for the contribution! Initial automated review looks good. Verdict: Looks good for a final review by the team. Removes the eager Redis Checked: security, performance, correctness, tests, conventions. No API routes or auth changes. Triggered by: new PR opened |
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Summary
What â The
locking-redisprovider's Redis client is now closed when the application shuts down.Why â No code ever closed the provider's Redis client.
LockingModuleServicehad no__hooks, andRedisLockingProviderhad no shutdown method. So anything that boots Medusa in-process more than once leaked ref'd TCP sockets, withmedusaIntegrationTestRunneras the main case. Other Redis-backed modules (cache-redis, event-bus-redis, workflow-engine-redis) already close their connections on shutdown.How
packages/modules/providers/locking-redis/src/services/redis-lock.ts: addedshutdown(), which callsredisClient.disconnect(). This is what cache-redis does.packages/modules/locking/src/services/locking-module.ts: added__hooks.onApplicationShutdown, which delegates to the provider service. This follows the analytics module's pattern.packages/modules/locking/src/services/locking-provider.ts: addedshutdown(). It calls the optionalshutdown()on each registeredlp_*provider. Providers without the method, such as in-memory, are skipped.Testing
locking-redis/src/loaders/__tests__/index.spec.tsruns the real loader against an in-process TCP stub. "should close the Redis connection on shutdown" failed before the fix because the provider had no shutdown method. It passes now.locking/integration-tests/__tests__/shutdown.spec.tsuses a fixture provider. Before the fix the module's shutdown hook made 0 calls to the provider'sshutdown(); now it makes 1.Checklist
Additional Context
MedusaAppMigrateUp,MedusaAppGetLinksExecutionPlanner), which create no module instance with hooks, so those loads can still leave a connection open.locking-redisintegration spec, because it needs a live Redis.src(resolve: <cwd>/src), so it doesn't depend on a prior build.medusajs/caching-redisseems to follow the same pattern. It creates and pings its client at load time, and nothing disconnects it on shutdown.Fixes #17220
ðĪ Generated with Claude Code