MagicStack / asyncpg

A fast PostgreSQL Database Client Library for Python/asyncio.
Apache License 2.0
6.88k stars 399 forks source link

Check whether on_data future is done before setting result/exception #1032

Closed rohitsanj closed 1 year ago

rohitsanj commented 1 year ago

To fix the following error:

Fatal error: protocol.data_received() call failed.
protocol: <asyncpg.connect_utils.TLSUpgradeProto object at 0x7f7711fd9e70>
transport: <_SelectorSocketTransport fd=653 read=polling write=<idle, bufsize=0>>

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 876, in _read_ready__data_received
    self._protocol.data_received(data)
  File "/srv/noteable/.venv/lib/python3.10/site-packages/asyncpg/connect_utils.py", line 665, in data_received
    self.on_data.set_result(True)
asyncio.exceptions.InvalidStateError: invalid state
rohitsanj commented 1 year ago

🤦

To all the watchers of this repository, sorry for the spam. I meant to raise this PR against a fork of this repository.