tortoise / tortoise/tortoise-orm

"Lost connection to mysql" in the scenario of master-slave switchover of mysql

Open
#1,360 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

Describe the bug
When I make the MySQL master as slave and slave as master, I found that the connections in used were block about 15min, and then I got the exception "tortoise.exceptions.OperationalError: (2013, 'Lost connection to MySQL server during query')".

To Reproduce
tortoise-orm 0.17.8
mysql

Expected behavior
automatic retry, when the connection fail

Additional context
I found that before version 0.14.2, reconnection was supported through the retry_connection decorator. But after version 0.15.0, the reconnect was canceled.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure with tortoise-orm 0.17.8 and MySQL during a master-slave switchover. Review the historical retry_connection decorator and the connection handling changed after version 0.14.2; done means an in-use connection recovers automatically after the failure and has regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, python
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.