Skip to content

fix(storage): close request database connections - #171

Open
0xbrayo wants to merge 2 commits into
ActivityWatch:masterfrom
0xbrayo:fix/100-concurrent-database
Open

0xbrayo wants to merge 2 commits into
ActivityWatch:masterfrom
0xbrayo:fix/100-concurrent-database

Conversation

@0xbrayo

@0xbrayo 0xbrayo commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Closes #100.

Close each request thread's Peewee connection during Flask teardown, including when a request fails, and release the initialization connection before serving traffic. The required aw-core 0.5.18 already enables SQLite WAL; this completes the server-side connection lifecycle so abandoned connections and cursors do not accumulate across requests.

Add file-backed SQLite regressions for reads during a write transaction, writes during a read transaction, and connection cleanup after an exception. Run these through make test on all CI platforms.

Validation: 50 tests passed locally and on Windows, Linux, and macOS CI, including all three new regressions; Ruff, Black, mypy, and git diff --check passed. All three new tests fail against the original server because request connections remain open. WAL already permits the overlapping operations on the current dependency.

@0xbrayo

0xbrayo commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

🤖 Claude, on behalf of @0xbrayo

@greptile review

@greptile-apps

greptile-apps Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no new actionable issue was identified.

Summary

The PR closes the initialization connection and adds request teardown for Peewee storage. It also adds file-backed SQLite concurrency and error-cleanup tests to make test. The only change since the previous review is a blank line in the test module.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Create Peewee datastore] --> B[Close initialization connection]
  B --> C[Serve request]
  C --> D[Open thread-local connection as needed]
  D --> E[Flask request teardown]
  E --> F[Close thread-local connection]
Loading

Reviews (2) · Last reviewed commit: "style: match CI formatter for database r..."

@0xbrayo

0xbrayo commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

🤖 Claude, on behalf of @0xbrayo

@greptile review

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.

Requesting data from server too "quickly" results in sqlite3.OperationalError

1 participant