-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
AssertionError: "assert transport is not None" in aiohttp.web_request.BaseRequest.__init__ #7258
Comments
No, that doesn't suppress it, it
Because of the above, this won't make any difference (edit: Or maybe it would, given the next comment). We've been looking at a potentially related issue though: #6978 (comment) |
I think it's actually caused by the same issue. On connection_lost, transport is set to None: But, in 3.8, we no longer cancel the handler. Fancy taking a go at creating a test to reproduce this in the CI? |
Same issue in aiohttp==3.8.5
|
Describe the bug
We are using aiohttp 3.8.3 and occasionally encounter the following error:
As I understand it, the error occurs due to the following sequence of actions:
First, the
web_protocol.RequestHandler.start
method is executed:The
await self._waiter
line is wrapped in a try-except block that suppressesCancelledError
. However, it is generally considered bad practice to catchCancelledError
without re-raising it becauseawait something()
can raiseCancelledError
for two entirely different reasons:something()
that being awaiting was cancelled;I believe the second scenario is what we are experiencing in this error. The connection was closed from the client side; the transport was set to
None
, andweb_protocol.RequestHandler.start
itself was canceled. However, theCancelledError
was mistakenly suppressed, assuming it was related toself._waiter
. As a result,web_protocol.RequestHandler.start
continued executing, and when callingrequest = self._request_factory(...)
, an assertion error occurred because the transport had already been closed.As a quick fix, it is possible to check if
self.transport is None
before callingself._request_factory(...)
, and, if True, raiseCancelledError
that was swallowed previously (not sure if this fix is completely correct though).To Reproduce
Probably the error arises when the connection is closed from the client side before the server is able to start the request handling.
Expected behavior
When a connection is closed from the client side, the code should work without any
AssertionError
exceptionsLogs/tracebacks
Python Version
3.8.4
aiohttp Version
3.8.3
multidict Version
irrelevant
yarl Version
irrelevant
OS
Windows, Linux
Related component
Server
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: