tortoise / tortoise/tortoise-orm

ConnectionDoesNotExistError, connection was closed in the middle of operation

Open
#1,598 3 comments 0 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

Hello
This exception rarely occures in our prod environment and I'm wondering if it's possible to fix it somehow, maybe by using some retry logic in queries.
We use tortoise along with FastAPI. Our default configuration is 10 MIN/MAX database pool size and 2 uvicorn workers.
I found the same issue https://github.com/tortoise/tortoise-orm/issues/134. That user created fork of this repo and tried to add logic with retry. Is this retry approach suitable for solving this problem?

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 reading issue #134 and the linked fork's tortoise/backends/asyncpg/client.py, then trace how Tortoise handles a connection closing during an operation. Reproduce the failure if possible and establish whether retrying is safe; the issue needs a defined failure scenario, scope, and acceptance criteria before completion can be judged.

Written by the indexing model from the issue text.

Assessment

Tech stack
fastapi, python
Domain
backend, database
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.