[PR #35] [MERGED] fix(history): implement thread-safe connection pool for SQLite to fix resource leaks #87

Closed
opened 2026-10-18 21:14:16 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/oikb/pull/35
Author: @mhajder
Created: 6/6/2026
Status: ✅ Merged
Merged: 7/17/2026
Merged by: @tjbck

Base: main ← Head: fix/history


📝 Commits (1)

  • a88b27c fix(history): implement thread-safe connection pool for SQLite to fix resource leaks

📊 Changes

1 file changed (+107 additions, -51 deletions)

View changed files

📝 src/oikb/history.py (+107 -51)

📄 Description

Refactors SyncHistory to use a queue.Queue connection pool instead of threading.local().

Previously, connections tied to threading.local() in a background worker pool would remain open until the thread died, leading to a steady leak of open file descriptors and locked connections.

Changes:

  • Replaced threading.local() with a bounded queue.Queue pool (size=5) of sqlite3.Connection objects configured with check_same_thread=False.
  • Safely wrapped the initial schema connection in a try...finally block to ensure close() is called, fixing a silent file lock leak.
  • Added PRAGMA synchronous=NORMAL alongside journal_mode=WAL for drastically improved concurrent write performance without sacrificing durability.
  • Updated all database operations to borrow from the pool using a context manager, allowing true multi-threaded concurrency (concurrent readers/writers via WAL) while strictly bounding the total number of open database connections.
  • Updated close() to gracefully drain the queue and explicitly terminate all pooled connections.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/oikb/pull/35 **Author:** [@mhajder](https://github.com/mhajder) **Created:** 6/6/2026 **Status:** ✅ Merged **Merged:** 7/17/2026 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `main` ← **Head:** `fix/history` --- ### 📝 Commits (1) - [`a88b27c`](https://github.com/open-webui/oikb/commit/a88b27c88cf39ba8ebc6446c26c2071d0b4309da) fix(history): implement thread-safe connection pool for SQLite to fix resource leaks ### 📊 Changes **1 file changed** (+107 additions, -51 deletions) <details> <summary>View changed files</summary> 📝 `src/oikb/history.py` (+107 -51) </details> ### 📄 Description Refactors `SyncHistory` to use a `queue.Queue` connection pool instead of `threading.local()`. Previously, connections tied to `threading.local()` in a background worker pool would remain open until the thread died, leading to a steady leak of open file descriptors and locked connections. Changes: - Replaced `threading.local()` with a bounded `queue.Queue` pool (size=5) of `sqlite3.Connection` objects configured with `check_same_thread=False`. - Safely wrapped the initial schema connection in a `try...finally` block to ensure `close()` is called, fixing a silent file lock leak. - Added `PRAGMA synchronous=NORMAL` alongside `journal_mode=WAL` for drastically improved concurrent write performance without sacrificing durability. - Updated all database operations to borrow from the pool using a context manager, allowing true multi-threaded concurrency (concurrent readers/writers via WAL) while strictly bounding the total number of open database connections. - Updated `close()` to gracefully drain the queue and explicitly terminate all pooled connections. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-18 21:14:16 +00:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
open-webui/oikb#87
No description provided.