fix(db): don't expire global or active emote sets during cleanup - #1255
Open
FacundoGimenez wants to merge 2 commits into
Open
fix(db): don't expire global or active emote sets during cleanup#1255FacundoGimenez wants to merge 2 commits into
FacundoGimenez wants to merge 2 commits into
Conversation
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.
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:
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
Fixes #932
Types of changes
What types of changes does your code introduce to 7TV?
Put an
xin the boxes that applyChecklist
Put an
xin 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.