Repository navigation
Conversation
disconnectAll() called use() on every configured store, so it created every store the application never used, along with its drivers and bus, only to disconnect it right away. Disconnect the providers already cached in #driversCache instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BXNob8sjkiaor7KMhLkMmg
🦋 Changeset detectedLatest commit: b677e51 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
disconnectAll()callsthis.use(cache)on every configured store:bentocache/packages/bentocache/src/bento_cache.ts
Lines 271 to 273 in 4fcb763
use()creates a store's provider the first time it is called (#createProvider()→new CacheStack()→ L1/L2 driver factories andnew Bus(), which subscribes to the bus channel). SodisconnectAll()creates every store the application never used, with its drivers and bus, only to disconnect it right away. This contradicts the method's doc comment: "Disconnect all cache connections created by the manager".Different from #122: that one creates a stray client for a store that is used, this one creates the whole store when it is not.
@adonisjs/cachecallsdisconnectAll()when the application shuts down. In an AdonisJS app that declares a Redis store next to a memory default, every Ace command goes through this on exit, including commands that never touch the Redis store.Reproduction
Expected: nothing happens for the
redisstore, since it was never created.Observed (Node 22):
@boringnode/bus0.9.2, ioredis 5.11.1main(4fcb763),@boringnode/bus0.10.0, ioredis 5.11.1 or 6.0.0redisstore created[ioredis] Unhandled error event: Error: connect ECONNREFUSED 127.0.0.1:1printed 21 times. After about 10 s,disconnectAll()rejects withMaxRetriesPerRequestError: Reached the max retries per request limit (which is 20). A secondMaxRetriesPerRequestErroris unhandled and the process exits with code 1.disconnectAll()resolvesfailed to subscribe to bus channel(channel: bentocache.notifications:redis)On
mainthe connection and the rejection are gone thanks to@boringnode/bus0.10, which disconnects a connection that is not ready yet instead of callingquit(), and to #129, which catches the subscription failure. The root cause is still there: the unused store is created on everydisconnectAll(), and its bus subscription fails and is logged as an error. In an AdonisJS app that error goes to the app logger on every command exit.Change
disconnectAll()now disconnects the providers in#driversCacheinstead of callinguse()on every configured store name:async disconnectAll(): Promise<void> { - await Promise.all(Object.keys(this.#stores).map(cache => this.use(cache).disconnect())) + await Promise.all([...this.#driversCache.values()].map(cache => cache.disconnect())) }Why this keeps the current behaviour for every store that was used:
use()is the only place that creates a provider, and it stores every provider it creates in#driversCache. The default-store shortcuts (get(),set(),namespace(), and so on) andclearAll()all go throughuse().#driversCachehas no driver, client or bus to close.Cache.disconnect()as before (L1, L2 and bus), and the providers stay in#driversCache, as they did before.A patch changeset is included.
Test
disconnectAll does not create stores that were never used, in theBento Cachegroup oftests/bento_cache.spec.ts, wraps the L1 factory of an unused memory store and counts its calls:expected 1 to equal +0The existing tests that call
disconnectAll()after using Redis stores keep covering the disconnection of created stores.Checked locally on Node 22:
pnpm typecheck,pnpm lintandpnpm format:checkpass.tests/drivers/{knex,kysely}/{mysql,postgres}.spec.ts,tests/drivers/orchid/postgres.spec.tsandtests/drivers/dynamodb.spec.ts. This change does not touch them.Not changed
clearAll()still iterates over every configured store. Clearing has to reach persistent L2 data even when the store was not used in this process, so creating the store there is expected.