-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
ClientWebSocketResponse.close_code will be None when there are concurrent async task receiving data and closing connection #7306
Copy link
Copy link
Closed
Labels
Description
Describe the bug
If one asyncio task is waiting on receiving data and another asyncio task is closing the connection. The ClientWebSocketResponse.close_code will be None after connection closed.
It looks like the following is happening:
close()called and feedWS_CLOSING_MESSAGE:Lines 191 to 193 in fde452d
if self._waiting is not None and not self._closed: self._reader.feed_data(WS_CLOSING_MESSAGE, 0) await self._waiting receive()receivedWS_CLOSING_MESSAGE, markself._closingto be True:Lines 285 to 286 in fde452d
elif msg.type == WSMsgType.CLOSING: self._closing = True close()(after sent out the close message to server) findself._closingis True, close the response and return, WITHOUT settingself._close_code:Lines 210 to 212 in fde452d
if self._closing: self._response.close() return True
To Reproduce
See the steps in https://github.com/wenleix/aiohttp_recv_upon_close
Expected behavior
Expect to have closed code 1000, i.e.
Waiting for message
Closed code: 1000
Logs/tracebacks
The actual result is :
Waiting for message
Closed code: None
### Python Version
```console
$ python --version
Python 3.9.13
### aiohttp Version
```console
$ python -m pip show aiohttp
Name: aiohttp
Version: 3.8.4
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author:
Author-email:
License: Apache 2
Requires: aiosignal, async-timeout, attrs, charset-normalizer, frozenlist, multidict, yarl
Required-by:
### multidict Version
```console
$ python -m pip show multidict
Name: multidict
Version: 6.0.4
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: [email protected]
License: Apache 2
Requires:
Required-by: aiohttp, yarl
### yarl Version
```console
$ python -m pip show yarl
Name: yarl
Version: 1.9.2
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl/
Author: Andrew Svetlov
Author-email: [email protected]
License: Apache-2.0
Requires: idna, multidict
Required-by: aiohttp
### OS
macOS
### Related component
Client
### Additional context
_No response_
### Code of Conduct
- [X] I agree to follow the aio-libs Code of Conduct
Reactions are currently unavailable