Skip to content

fix: close IndexedDB connections after each cache operation - #241

Open
pranayr710 wants to merge 1 commit into
AOSSIE-Org:mainfrom
pranayr710:fix/indexeddb-connection-leak
Open

pranayr710 wants to merge 1 commit into
AOSSIE-Org:mainfrom
pranayr710:fix/indexeddb-connection-leak

Conversation

@pranayr710

@pranayr710 pranayr710 commented Sep 19, 2026

Copy link
Copy Markdown

Fixes #216

Problem

openDB() opens a fresh IndexedDB connection on every cacheGet, cacheSet and cacheClear call, and the returned handle is never closed. Analyzing an organization with several repositories fires hundreds of these cache calls (contributors, issues, pulls per repo), so hundreds of IDBDatabase connections accumulate in the tab over a single session.

Fix

Call db.close() right after starting the transaction in each of the three functions. Per the IndexedDB spec, close() only takes effect once any in-flight transaction on that connection settles, so this is safe — it doesn't cut off the read/write in progress, it just stops the connection from lingering afterward.

1 file changed, +10/−5.

Verification

jsdom (this repo's test environment) doesn't implement IndexedDB, so I verified with a throwaway Node script using fake-indexeddb (not committed — installed with --no-save for local verification only, then removed): instrument indexedDB.open to count connections opened vs. explicitly closed, then run a representative sequence of 5 cache operations (cacheSet ×2, cacheGet ×2, cacheClear ×1).

opened closed leaked
before this fix 5 0 5
after this fix 5 5 0

The existing test suite (49 tests, 6 files) still passes unchanged.

Note

I found this issue unclaimed — no maintainer or reporter statement of intent to fix it — and built the patch directly given the volume of open issues here. Happy to adjust scope or close if a maintainer is already working this.

Summary by CodeRabbit

  • Bug Fixes
    • Improved cache database connection handling to help prevent lingering connections during cache reads, writes, and clearing.
    • Preserved existing expiration behavior and success or error results.

openDB() opens a fresh IndexedDB connection on every cacheGet/cacheSet/
cacheClear call, and the returned handle was never closed. Analyzing an
organization with several repos issues hundreds of these calls, so
hundreds of IDBDatabase connections accumulate in the tab - each one
counted in devtools, contributing to memory growth and able to block a
future version upgrade of the database.

IDBDatabase.close() defers until any in-flight transaction on that
connection settles, so it's safe to call immediately after starting the
transaction rather than waiting on its completion event.

Fixes AOSSIE-Org#216
@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: AOSSIE-Org/OrgExplorer/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: c83c8635-73af-4d65-b0bc-4e9be220343a

📥 Commits

Reviewing files that changed from the base of the PR and between 0b1110e and 36eb446.

📒 Files selected for processing (1)
  • src/services/github.js

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

The cache functions now create IndexedDB requests or transactions before returning promises. Each function closes its database connection immediately. Existing TTL, success, and error handling remain unchanged.

Changes

IndexedDB cache cleanup

Layer / File(s) Summary
Cache operation lifecycle
src/services/github.js
cacheGet, cacheSet, and cacheClear create their IndexedDB work before constructing completion promises and close the database connection immediately. Existing results remain unchanged.

Priority: ⬆️ High

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: High

Suggested labels: Typescript Lang

Suggested reviewers: ri1tik

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #216 requires closing every database handle created by openDB() in cacheGet, cacheSet, and cacheClear. The reviewed changes start each request or transaction, call db.close() immediate…
Out of Scope Changes check ✅ Passed The whole-PR change is limited to src/services/github.js. It adds connection cleanup to the three cache functions named by issue #216 and does not introduce unrelated behavior.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: closing IndexedDB connections after cache operations.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit reads each line,
The patch grows clear beneath the moon,
Small changes hop in place,
Tests guard the garden path,
Reviews bloom before the dawn.

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added bug Something isn't working javascript JavaScript/TypeScript changes size/S 11-50 lines changed first-time-contributor First time contributor and removed size/S 11-50 lines changed labels Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working first-time-contributor First time contributor javascript JavaScript/TypeScript changes size/S 11-50 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Unclosed IndexedDB database connections in github.js cause memory leaks

1 participant