Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When cancelling websocket, exception thrown: aiohttp._websocket.reader_c.WebSocketDataQueue' object has no attribute 'is_eof' #9880

Closed
1 task done
egoldschmidt opened this issue Nov 14, 2024 · 11 comments · Fixed by #9883
Assignees
Labels
bug regression Something that used to work stopped working "as before" after upgrade

Comments

@egoldschmidt
Copy link

Describe the bug

When closing a websocket connection (in response to task.cancel() I think), I am seeing errors of this form:

AttributeError: 'aiohttp._websocket.reader_c.WebSocketDataQueue' object has no attribute 'is_eof'
^^^^^^^^^^^^^^^^^^^^
or (self._payload is not None and not self._payload.is_eof())
File "/home/appuser/.venv/lib/python3.12/site-packages/aiohttp/client_proto.py", line 55, in should_close
^^^^^^^^^^^^^^^^^^^^^
if self._force_close or should_close or protocol.should_close:
File "/home/appuser/.venv/lib/python3.12/site-packages/aiohttp/connector.py", line 705, in _release
self._connector._release(self._key, self._protocol)
File "/home/appuser/.venv/lib/python3.12/site-packages/aiohttp/connector.py", line 197, in release
self._connection.release()
File "/home/appuser/.venv/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 945, in __del__
Traceback (most recent call last):
Exception ignored in: <function ClientResponse.__del__ at 0x7faf9467ff60>

A cursory reading of _websocket/reader.py seems to suggest that indeed there is no is_eof function.

To Reproduce

Start a websocket and call .cancel() on the task or stop the event loop

Expected behavior

No error

Logs/tracebacks

AttributeError: 'aiohttp._websocket.reader_c.WebSocketDataQueue' object has no attribute 'is_eof'
^^^^^^^^^^^^^^^^^^^^
or (self._payload is not None and not self._payload.is_eof())
File "/home/appuser/.venv/lib/python3.12/site-packages/aiohttp/client_proto.py", line 55, in should_close
^^^^^^^^^^^^^^^^^^^^^
if self._force_close or should_close or protocol.should_close:
File "/home/appuser/.venv/lib/python3.12/site-packages/aiohttp/connector.py", line 705, in _release
self._connector._release(self._key, self._protocol)
File "/home/appuser/.venv/lib/python3.12/site-packages/aiohttp/connector.py", line 197, in release
self._connection.release()
File "/home/appuser/.venv/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 945, in __del__
Traceback (most recent call last):
Exception ignored in: <function ClientResponse.__del__ at 0x7faf9467ff60>


### Python Version

```console
$ python --version

Python 3.12.7

aiohttp Version

$ python -m pip show aiohttp

Name: aiohttp
Version: 3.11.0
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author:
Author-email:
License: Apache 2
Location: /Users/evan/Projects/portola/livekit-worker/.venv/lib/python3.12/site-packages
Requires: aiohappyeyeballs, aiosignal, attrs, frozenlist, multidict, propcache, yarl
Required-by: livekit-agents, livekit-api

multidict Version

$ python -m pip show multidict

Name: multidict
Version: 6.1.0
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: /Users/evan/Projects/portola/livekit-worker/.venv/lib/python3.12/site-packages
Requires:
Required-by: aiohttp, yarl

propcache Version

$ python -m pip show propcache

Name: propcache
Version: 0.2.0
Summary: Accelerated property cache
Home-page: https://github.com/aio-libs/propcache
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache-2.0
Location: /Users/evan/Projects/portola/livekit-worker/.venv/lib/python3.12/site-packages
Requires: 
Required-by: aiohttp, yarl

yarl Version

$ python -m pip show yarl

Name: yarl
Version: 1.17.1
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache-2.0
Location: /Users/evan/Projects/portola/livekit-worker/.venv/lib/python3.12/site-packages
Requires: idna, multidict, propcache
Required-by: aiohttp

OS

Debian

Related component

Client

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@egoldschmidt
Copy link
Author

Oh one important note: this was definitely not happening on 3.10.10

@bdraco bdraco self-assigned this Nov 14, 2024
@bdraco
Copy link
Member

bdraco commented Nov 14, 2024

Looks like we don’t have a test for this case. Should be an easy fix

@bdraco bdraco added the regression Something that used to work stopped working "as before" after upgrade label Nov 14, 2024
@bdraco
Copy link
Member

bdraco commented Nov 14, 2024

Thanks for including the full trace in the initial report

@egoldschmidt
Copy link
Author

Happy to help! Thanks for the quick ACK

@bdraco
Copy link
Member

bdraco commented Nov 14, 2024

I'm assuming you don't notice any production impact other than the trace in the log?

@egoldschmidt
Copy link
Author

I believe that is the case, yes

@bdraco
Copy link
Member

bdraco commented Nov 14, 2024

Not having any luck replicating this or writing a test for it. It seems there has to be a payload present as well

@bdraco
Copy link
Member

bdraco commented Nov 14, 2024

It looks like this can only happen if the ClientResponse is destroyed without being properly closed

@bdraco
Copy link
Member

bdraco commented Nov 14, 2024

Its likely something isn't closing the WebSocket connections and they are only getting cleaned up in garbage collection. Likely after cancellation in your case from the opening text. If loop.debug is on you'll probably see an unclosed resource warning as well.

@bdraco
Copy link
Member

bdraco commented Nov 14, 2024

It took me a while to figure out what why I couldn't replicate it in the tests. Our test harness was being a bit too helpful and cleaning up the unclosed WebSocket connections so we would never hit this path.

#9883

@bdraco
Copy link
Member

bdraco commented Nov 14, 2024

3.11.2 published to PyPI with the fix in #9883

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug regression Something that used to work stopped working "as before" after upgrade
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants