Skip to content

fix(db): don't expire global or active emote sets during cleanup - #1255

Open
FacundoGimenez wants to merge 2 commits into
SevenTV:masterfrom
FacundoGimenez:fix/emote-set-expiration
Open

fix(db): don't expire global or active emote sets during cleanup#1255
FacundoGimenez wants to merge 2 commits into
SevenTV:masterfrom
FacundoGimenez:fix/emote-set-expiration

Conversation

@FacundoGimenez

Copy link
Copy Markdown

Proposed changes

Fixes the bug where opening a second Twitch channel would, at some point, kill 7TV emotes in every open tab — and only a full Chrome restart brought them back.

Root cause. When a new tab connected, the SharedWorker scheduled an IndexedDB cleanup (expireDocuments) that fired ~2.5–15s later and deleted every emote set older than 1 hour, including the sets of the channels you were currently watching and the global emote sets. Since IndexedDB persists across sessions, this could also trigger right after starting Chrome when the database still had cached emote data from previous sessions. Global sets are fetched only once per worker instance and never re-fetched, so once deleted they stayed gone until the worker was recreated. Reloading tabs didn't help because the worker stays alive, which is why the only working recovery was closing Chrome.

Fix. expireDocuments() in src/db/idb.ts now keeps global emote sets and sets still referenced by an active (exempt) channel, and only expires sets that are genuinely stale and no longer used. While investigating I also fixed two smaller issues:

  • Dexie7.ready() never set its _ready flag, so a successful DB open was re-attempted on every call.
  • WorkletTarget.listenUntil() removed the wrong listener (the predicate instead of the actual handler), leaking listeners on every channel navigation.

I also added instance-correlated logging (port sequence, channel id/login, subscribe/unsubscribe, reconnect, cleanup runs) to the worker and site scripts to make this kind of issue traceable across tabs.

Tests. Added a vitest + fake-indexeddb setup (yarn test) with 9 tests covering the cleanup behaviour (global sets survive, active channel sets survive, stale sets are still removed), the regression scenario of opening a new tab, ready() idempotence, and the listenUntil leak. The IndexedDB tests fail against the previous behaviour and pass with the fix. yarn test, yarn lint and vue-tsc --noEmit pass locally. I also added a yarn test step to the CI workflow and a changelog entry.

How to reproduce the original bug

  1. Use a Chrome profile that has watched Twitch with 7TV before, so IndexedDB still has emote data from previous sessions (older than 1h).
  2. Start Chrome and open a Twitch channel.
  3. Open a second channel in another tab.
  4. Before the fix: within ~15s the stale cached emote sets are wiped from IndexedDB (including global emotes, which don't come back until Chrome is restarted). After the fix: nothing that's in use gets deleted.

Fixes #932

Types of changes

What types of changes does your code introduce to 7TV?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged

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.

[BUG] emotions disappear when you stay on stream for a long time

1 participant