-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Normalize asyncio writer close races #4217
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
base: master
Are you sure you want to change the base?
Changes from all commits
2132282
d7dd61c
fa2279f
4588fa1
7c3a840
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1143,8 +1143,20 @@ async def check_health(self): | |
| ) | ||
|
|
||
| async def _send_packed_command(self, command: Iterable[bytes]) -> None: | ||
| self._writer.writelines(command) | ||
| await self._writer.drain() | ||
| writer = self._writer | ||
| if writer is None: | ||
| raise ConnectionError("Connection closed while writing") | ||
| try: | ||
| writer.writelines(command) | ||
| await writer.drain() | ||
| except AttributeError as error: | ||
|
petyaslavova marked this conversation as resolved.
|
||
| if str(error) != "'NoneType' object has no attribute 'writelines'": | ||
| raise | ||
| raise ConnectionError("Connection closed while writing") from error | ||
|
petyaslavova marked this conversation as resolved.
|
||
| except TypeError as error: | ||
| if str(error) != "'NoneType' object is not callable": | ||
| raise | ||
| raise ConnectionError("Connection closed while writing") from error | ||
|
cursor[bot] marked this conversation as resolved.
Comment on lines
+1152
to
+1155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For the reported Python 3.12 close race, the traceback in #3546 fails inside Useful? React with 👍 / 👎.
Comment on lines
+1157
to
+1159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In the final code, this branch still identifies the closed-transport race solely by AGENTS.md reference: AGENTS.md:L120-L123 Useful? React with 👍 / 👎. |
||
|
|
||
| async def send_packed_command( | ||
| self, command: Union[bytes, str, Iterable[bytes]], check_health: bool = True | ||
|
|
@@ -1164,8 +1176,7 @@ async def send_packed_command( | |
| self._send_packed_command(command), self.socket_timeout | ||
| ) | ||
| else: | ||
| self._writer.writelines(command) | ||
| await self._writer.drain() | ||
| await self._send_packed_command(command) | ||
| except asyncio.TimeoutError: | ||
| await self.disconnect(nowait=True) | ||
| raise TimeoutError("Timeout writing to socket") from None | ||
|
|
@@ -1393,7 +1404,13 @@ def pack_commands(self, commands: Iterable[Iterable[EncodableT]]) -> List[bytes] | |
|
|
||
| def _socket_is_empty(self): | ||
| """Check if the socket is empty""" | ||
| return len(self._reader._buffer) == 0 | ||
| reader = self._reader | ||
| if reader is None: | ||
| raise ConnectionError("Connection closed while reading") | ||
| try: | ||
| return len(reader._buffer) == 0 | ||
| except AttributeError as error: | ||
| raise ConnectionError("Connection closed while reading") from error | ||
|
|
||
| async def process_invalidation_messages(self): | ||
| while not self._socket_is_empty(): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.