MagicStack / asyncpg

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

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

Closed rohitsanj closed 4 months ago

rohitsanj commented 1 year ago

This should fix the following error seen in one of Noteable's production servers recently:

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