Skip to content

feat(db): SQL auto reconnect - #33

Open
Rushaway wants to merge 1 commit into
masterfrom
feat/sql-auto-reconnect
Open

Rushaway wants to merge 1 commit into
masterfrom
feat/sql-auto-reconnect

Conversation

@Rushaway

Copy link
Copy Markdown
Member

Closes #13

Summary

Adds SQL auto reconnect, inspired by SourceBans++ (lazy reconnect guarded by a "connecting" flag).

  • Connect failure: no more SetFailState(). The error is logged and a new connect attempt is scheduled after sm_vip_test_reconnect_interval seconds (new cvar, default 30, min 5).
  • Lost connection: query callbacks go through a HandleQueryError() helper. When the error looks like a lost connection (gone away, Lost connection, Can't connect, Broken pipe), the dead handle is dropped and a reconnect starts.
  • Null handle guards: sm_testvip / sm_viptest, sm_clear_viptest, OnClientPostAdminCheck and GiveVIPToClient all check the database first. Players get a new VIP_DB_UNAVAILABLE message (en/ru/fi/fr). Test VIP is no longer granted when it can't be written to the database.
  • Resync: once the connection is (re)established, in-game authorized players are reloaded so players who joined during the outage get their test VIP back. This also covers late plugin loads.
  • Version bumped to 1.0.10.

Test plan

  • CI build passes
  • MySQL: start with the DB down → plugin keeps running, logs retries, connects once the DB is back
  • MySQL: restart the DB while the server is running → next query logs the lost connection and the plugin reconnects
  • sm_testvip while the DB is down → VIP_DB_UNAVAILABLE message, no VIP granted
  • SQLite (no vip_test entry in databases.cfg) still works

🤖 Generated with Claude Code

- Retry the database connection on a timer instead of calling
  SetFailState() when the connect fails
  (new cvar sm_vip_test_reconnect_interval, default 30s).
- Detect lost connections in query callbacks ("gone away",
  "Lost connection", ...), drop the dead handle and reconnect.
- Guard every query path against a null database handle and tell
  the player the database is unavailable (new VIP_DB_UNAVAILABLE
  phrase). Test VIP is no longer granted if it can't be saved.
- Reload in-game players once the connection is (re)established.

Bumped plugin version to 1.0.10.

Closes #13

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings September 29, 2026 18:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

feature: Sql auto reconnect

2 participants