Repository navigation
fix(db): reconnect SurrealDB connections that drop - #123
Merged
Merged
Conversation
…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
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.
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/statusand 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 timeouton every request. The pool inapp/domain/store.pykept 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.pydoes this: it fails on main withConnectionClosedErrorand passes here.Types of changes
!in the title)Checklist:
docs/accordingly.## UnreleasedinCHANGELOG.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) andtest_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