Skip to content

fix: remove stale cache entries when last observer unsubscribes#4569

Closed
tenderdeve wants to merge 1 commit intowevm:mainfrom
tenderdeve:fix/4390-observe-leaks-empty-arrays-in-listenerscache-after
Closed

fix: remove stale cache entries when last observer unsubscribes#4569
tenderdeve wants to merge 1 commit intowevm:mainfrom
tenderdeve:fix/4390-observe-leaks-empty-arrays-in-listenerscache-after

Conversation

@tenderdeve
Copy link
Copy Markdown

Fixes #4390

When all listeners for an observerId call unwatch(), the unsubscribe function previously filtered them out but left an empty array behind in listenersCache (and a stale entry in cleanupCache). In long-running servers creating many short-lived clients, these empty entries accumulate indefinitely.

The fix deletes both cache entries when the last listener unsubscribes, instead of storing an empty array.

I also added a test that explicitly verifies cache cleanup — it checks that both listenersCache and cleanupCache still have entries while listeners remain, and are fully deleted after the last unwatch() call.

…#4390)

When all listeners for an observerId unsubscribe, delete the entries
from listenersCache and cleanupCache instead of leaving empty arrays
that accumulate indefinitely in long-running processes.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 1, 2026

@tenderdeve is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 1, 2026

⚠️ No Changeset found

Latest commit: a09a652

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@jxom jxom closed this May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

observe() leaks empty arrays in listenersCache after all listeners unsubscribe

2 participants