Skip to content

Comments

[feat] Add extra error output on lost server error to indicate possible SSL mismatch (#1584)#1609

Open
scottnemes wants to merge 1 commit intodbcli:mainfrom
scottnemes:feat/1584/add-additional-logging-server-lost
Open

[feat] Add extra error output on lost server error to indicate possible SSL mismatch (#1584)#1609
scottnemes wants to merge 1 commit intodbcli:mainfrom
scottnemes:feat/1584/add-additional-logging-server-lost

Conversation

@scottnemes
Copy link
Contributor

Description

In some edge cases like the cloud-sql-proxy, an SSL configuration mismatch (i.e. server not having SSL enabled, but client is forcing it) will result in a generic (2013, 'Lost connection to MySQL server during query') error. This error unfortunately can mean many things, but to help the user diagnose a potential issue this PR adds an error message to check SSL configuration if the error persists.

Resolves #1584 (with additional help from PR #1591)

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the AUTHORS file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

@github-actions
Copy link

Findings (ordered by severity)

  1. Potential crash on malformed OperationalError args
    In _connect, all branches index e1.args[0] without guarding for empty/short args. If pymysql raises an OperationalError with no args (it can happen in some driver edge cases), this will raise IndexError and hide the original failure. Consider guarding or using a helper like code = e1.args[0] if e1.args else None. This isn’t new in this PR, but this change adds another branch that relies on it, making the risk more visible.
    File: mycli/main.py:704

  2. Missing test for new user-facing message
    The new behavior is user-visible and should be verified. Add a unit test that forces SQLExecute to raise OperationalError with CR_SERVER_LOST and assert the extra guidance text is emitted. A CliRunner test can monkeypatch SQLExecute in test/test_main.py to simulate the error.
    File: test/test_main.py

No security concerns found in this change.

If you want, I can draft the test case.

@scottnemes scottnemes self-assigned this Feb 22, 2026
self.echo(
(
"Connection to server lost. If this error persists, it may be a mismatch between the server and "
"client SSL configuration. To troubleshoot the issue, try --ssl-mode off or --ssl-mode on."
Copy link
Contributor

Choose a reason for hiding this comment

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

The message would be a little easier to parse visually with the option equal signs: --ssl-mode=off.

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.

Cannot connect to cloud-sql-proxy with passwordless login

2 participants