-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Connection class disconnects on BaseException #2103
Comments
Strangely in #2499 I found the opposite to be true. Similarly to asyncio's |
No, it is the application which decides, in response to a Timeout, to either
The Timout should leave the connection in the state that it was, so that the application can decide how to respond to the timout. Typically, the application can do something else, such as updating a progress bar, and then resume reading the response. |
As discussed on another thread,
this is true for |
The connection pool is optional. It is then, |
Note that the implementation in the description contains a race condition and will drop messages and/or corrupt the connection, in the worst case returning garbage data. |
Could you elaborate on that? I'd be interested in understanding which race condition you have in mind since I recently re-wrote all of the timeout code in async redis. |
The race condition is the situation described in more detail here. If the Interrupt does not arrive while the connection is idle (the way more common case) but happens to trigger at nearly the same time as a message arrives, the message reading gets interrupted and the connection corrupted. |
Hm, it would appear that it is the PythonParser which is unsafe, it doesn't maintain incomplete state, it intermixes IO operations with logic. You are right, an interruption of the python parser during read will leave it in a bad state. |
@kristjanvalur Does this issue still relevant or we can close it? |
Closing this, it is no longer relevant, much has changed in the mean time. |
Version: 4.2.2
Platform: Windows 11
Description: The methods
send_packed_command
andread_response
on theasyncio.connection.Connection
classhave exception handlers which catch
BaseException
and callself.disconnect()
before re-raising.This is rather unfortunate, because it makes it impossible to use an outer
Timeout
around redis methods. For example, the following pattern fails:This is because internally, the timeout will raise a
CancelledError
in the task. This is a base exception and isn't converted into a TimeoutError until higher in the call stack.Generally, BaseExceptions should not be caught. In this case, it would be prudent to change this to catch
Exception
instead.The text was updated successfully, but these errors were encountered: