8000 fix(db): reconnect SurrealDB connections that drop by adeelahmad · Pull Request #123 · adeelahmad/lense · GitHub
[go: up one dir, main page]

Skip to content

fix(db): reconnect SurrealDB connections that drop - #123

Merged
adeelahmad merged 2 commits into
mainfrom
claude/fix-notes-panel-crash-djzbr0
Oct 4, 2026
Merged

adeelahmad merged 2 commits into
mainfrom
claude/fix-notes-panel-crash-djzbr0

Conversation

@adeelahmad
Copy link
Copy Markdown
Owner

Requested by Adeel · project thread

Description

Before: after the backend's websocket to a SurrealDB server dropped (a keepalive ping timeout, e.g. after the machine slept, or a server restart), every request failed with 500 until the backend restarted. Opening a panel such as Notes on a resource page "broke the app", and sign-in, /auth/status and the health check failed too (the container showed unhealthy).

After: the backend replaces a dropped connection on its own. The next request works, and the log says SurrealDB connection dropped; reconnected.

Motivation and Context

Adeel's backend log showed websockets.exceptions.ConnectionClosedError: sent 1011 (internal error) keepalive ping timeout on every request. The pool in app/domain/store.py kept the closed connection and handed it out forever.

How: DB.conn() checks a server connection's websocket before handing it out and swaps a closed one for a fresh one. A connection that drops mid-query is replaced for the next query too (that query still fails rather than being resent, since it may have run). If the server is unreachable, the old connection stays and the next query tries again. Embedded databases are unaffected.

Steps to reproduce (if appropriate):

Run against a SurrealDB server, close the pool's websockets (what a ping timeout leaves), then query. tests/domain/test_store_reconnect.py does this: it fails on main with ConnectionClosedError and passes here.

Types of changes

  • Bug fix (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 change; ! in the title)

Checklist:

  • The title is a Conventional Commit.
  • My code follows the code style of this project (ruff, ruff format, mypy clean).
  • I added or updated tests.
  • My change requires documentation updates, and I have updated docs/ accordingly.
  • Users need more than the title to understand it, so I wrote it under ## Unreleased in CHANGELOG.md.

Full backend suite, embedded and against a SurrealDB 3.2.4 server: all pass except test_office_and_text_files_become_documents (LibreOffice, environmental) and test_sources_and_watched_folders, both of which fail identically on main in this container.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HLZZQqFnhFjprTPR4wrfdv


Generated by Claude Code

…very request

A server connection whose keepalive ping times out (or whose server restarts)
stayed in the pool closed, so every query on it failed with ConnectionClosedError
until the backend restarted: sign-in, auth status and every page 500ed.
The pool now checks a connection before handing it out and replaces one
that has closed or drops mid-query.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HLZZQqFnhFjprTPR4wrfdv
@adeelahmad adeelahmad self-assigned this Oct 4, 2026
@adeelahmad
adeelahmad merged commit 412146c into main Oct 4, 2026
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.

2 participants

0