tortoise / tortoise/tortoise-orm

Create a background task use asyncio.create_task, DB connection issue occurs

Open
#1,306 1 comment 1 reaction 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

Use Sanic , when received a request , add a background task to update DB by asyncio.create_task

this error occurs:

asyncpg.exceptions._base.InterfaceError: cannot call Connection.execute(): connection has been released back to the pool

the full trace is :

image

To Reproduce

DB: postgresql 12
Sanic: 22.9.0
tortoise: 0.19.2

image

Additional context

I also report this to Sanic, the feedback of creator of Sanic :

image

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

No repository file or test is named. Start by reproducing the asyncio.create_task failure with PostgreSQL 12, Sanic 22.9.0, and Tortoise 0.19.2, then trace the background task's database connection lifetime around the reported asyncpg InterfaceError. Done means the connection-release behavior is understood and a regression test or clearly scoped fix is identified.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.