MagicStack / MagicStack/asyncpg

cannot switch to state 15; another operation (2) is in progress

Open
#784 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
8.1k
Forks
468
PR merge metrics
No merged PRs in 30d

Description

* **asyncpg version**: 0.23.0
* **PostgreSQL version**: Aurora PostgreSQL 10.14
* **Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?**: RDS Aurora (and hard to repro)
* **Python version**: 3.9
* **Platform**: Linux
* **Do you use pgbouncer?**: no
* **Did you install asyncpg with pip?**: pip3.9 install --user
* **If you built asyncpg locally, which version of Cython did you use?**:
* **Can the issue be reproduced under both asyncio and [uvloop](https://github.com/magicstack/uvloop)?**: repro'd with uvloop

```
File "/root/.local/lib/python3.9/site-packages/asyncpg/pool.py", line 792, in __aexit__
await self.pool.release(con)
File "/root/.local/lib/python3.9/site-packages/asyncpg/pool.py", line 666, in release
return await asyncio.shield(ch.release(timeout))
File "/usr/lib/python3.9/asyncio/futures.py", line 284, in __await__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.9/asyncio/tasks.py", line 328, in __wakeup
future.result()
File "/usr/lib/python3.9/asyncio/futures.py", line 201, in result
raise self._exception
File "/usr/lib/python3.9/asyncio/tasks.py", line 256, in __step
result = coro.send(None)
File "/root/.local/lib/python3.9/site-packages/asyncpg/pool.py", line 218, in release
raise ex
File "/root/.local/lib/python3.9/site-packages/asyncpg/pool.py", line 208, in release
await self._con.reset(timeout=budget)
File "/root/.local/lib/python3.9/site-packages/asyncpg/connection.py", line 1311, in reset
await self.execute(reset_query, timeout=timeout)
File "lib/common.py", line 164, in execute
return await self._with_logger(super(PSQLLoggerMixin, self).execute)(*args, **kwargs)
File "lib/common.py", line 119, in wrapper
ret_val = await func(*args, **kwargs)
File "/root/.local/lib/python3.9/site-packages/asyncpg/connection.py", line 297, in execute
return await self._protocol.query(query, timeout)
File "asyncpg/protocol/protocol.pyx", line 338, in query
File "/usr/lib/python3.9/asyncio/futures.py", line 287, in __await__
return self.result() # May raise too.
File "/usr/lib/python3.9/asyncio/futures.py", line 201, in result
raise self._exception
File "asyncpg/protocol/protocol.pyx", line 331, in asyncpg.protocol.protocol.BaseProtocol.query
File "asyncpg/protocol/coreproto.pyx", line 1061, in asyncpg.protocol.protocol.CoreProtocol._simple_query
File "asyncpg/protocol/coreproto.pyx", line 768, in asyncpg.protocol.protocol.CoreProtocol._set_state
asyncpg.exceptions._base.InternalClientError: cannot switch to state 15; another operation (2) is in progress
```

Contributor guide

No contributing guide indexed for this repository

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 with asyncpg/pool.py around release, asyncpg/connection.py around reset, and asyncpg/protocol/coreproto.pyx around _set_state. Review the traceback and investigate the concurrent-operation path, noting that the report is hard to reproduce and was seen with uvloop and Aurora PostgreSQL. Done means the cause is reproducible or explained and the state-switch failure is corrected without breaking connection release.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
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.