Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

fix socket.error raises #1129

Merged
merged 16 commits into from Nov 29, 2021
Merged

Conversation

x0day
Copy link
Contributor

@x0day x0day commented Sep 16, 2021

Fixes #1121

What do these changes do?

fix raise aioredis.exceptions.ConnectionError instead of raw socket.error or its subclasses

Are there changes in behavior for the user?

no

Related issue number

#1121

@eneloop2
Copy link

eneloop2 commented Sep 16, 2021

This kind of bug appears in more than one place so it's not actually going to address all instances of ConnectionResetError being raised.

@x0day
Copy link
Contributor Author

x0day commented Sep 17, 2021

@eneloop2 @Andrew-Chen-Wang
#1121 (comment)
look at this, please consider this fix, thanks.

from aioredis.connection import NONBLOCKING_EXCEPTIONS

try:
    raise ConnectionResetError
except NONBLOCKING_EXCEPTIONS:
    print('aioredis catched!')
except Exception as exc:
    print("aioredis not catched!")

from redis.connection import NONBLOCKING_EXCEPTIONS

try:
    raise ConnectionResetError
except NONBLOCKING_EXCEPTIONS:
    print('redis-py catched')

@Andrew-Chen-Wang
Copy link
Collaborator

@x0day do you have hiredis installed by chance?

@x0day
Copy link
Contributor Author

x0day commented Sep 24, 2021

@x0day do you have hiredis installed by chance?

YES, it's not parse error, just aio-redis not consider socket error as NONBLOCKING_EXCEPTIONS.

@x0day
Copy link
Contributor Author

x0day commented Nov 6, 2021

@seandstewart can we get this in the PR #1156 ?

@x0day x0day mentioned this pull request Nov 22, 2021
5 tasks
Copy link
Collaborator

@Andrew-Chen-Wang Andrew-Chen-Wang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the message and PR!

@Andrew-Chen-Wang
Copy link
Collaborator

Please add a CHANGE file though

@x0day
Copy link
Contributor Author

x0day commented Nov 22, 2021

@Andrew-Chen-Wang thanks for the review!

@codecov
Copy link

codecov bot commented Nov 22, 2021

Codecov Report

Merging #1129 (b9cf282) into master (2ba15fb) will decrease coverage by 0.06%.
The diff coverage is 25.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1129      +/-   ##
==========================================
- Coverage   90.71%   90.64%   -0.07%     
==========================================
  Files          21       21              
  Lines        6872     6875       +3     
  Branches      793      794       +1     
==========================================
- Hits         6234     6232       -2     
- Misses        467      470       +3     
- Partials      171      173       +2     
Flag Coverage Δ
unit 90.56% <25.00%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aioredis/connection.py 77.15% <0.00%> (-0.52%) ⬇️
aioredis/exceptions.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2ba15fb...b9cf282. Read the comment docs.

@Andrew-Chen-Wang
Copy link
Collaborator

One thing to note is that from redis/redis-py@8c5a41b, this piece of code was dropped due to Python 2.7 dropping. How does this resolve a Windows specific error?

@x0day
Copy link
Contributor Author

x0day commented Nov 23, 2021

@Andrew-Chen-Wang

FYI: at redis/redis-py@8c5a41b, it's solve the problem by raise ConnectionError instead of raw socket.error, aioredis-py's is same here.

image

but aioredis-py didn't catch the OSError at the Connection.read_response. it's the difference.

https://github.com/redis/redis-py/blob/791f482dcb320f48cf950c4b2c6047d1981a8f67/redis/connection.py#L753-L756
https://github.com/aio-libs/aioredis-py/blob/2ba15fb6947fa2347d401ba436e362ad62ed38ff/aioredis/connection.py#L893-L907

so if socket.error in NONBLOCKING_EXCEPTIONS, ConnectionResetError will be catched at _read_from_socket , either handle the OSError in Connection.read_response also solve the bug.

should I need to update the PR, by catching the OSError in Connection.read_response like the redis-py implement?

@Andrew-Chen-Wang
Copy link
Collaborator

Yes, by catching the socket.error you mean? I'm surprised BaseException doesn't catch it, but at least by catching socket.error directly we can resolve this issue + be in paralle l with redis-py.

@x0day
Copy link
Contributor Author

x0day commented Nov 23, 2021

@Andrew-Chen-Wang can you review the PR again? thanks.

CHANGES/1129.bugfix Outdated Show resolved Hide resolved
aioredis/connection.py Show resolved Hide resolved
x0day and others added 3 commits November 23, 2021 10:15
Co-authored-by: Andrew Chen Wang <60190294+Andrew-Chen-Wang@users.noreply.github.com>
@Andrew-Chen-Wang
Copy link
Collaborator

failing ci

@x0day
Copy link
Contributor Author

x0day commented Nov 29, 2021

@Andrew-Chen-Wang sorry for late response, failing CI because this:

https://github.com/aio-libs/aioredis-py/blob/master/aioredis/exceptions.py#L10
https://github.com/redis/redis-py/blob/9db1eec71b443b8e7e74ff503bae651dc6edf411/redis/exceptions.py#L8

aioredis-py warped builtins.ConnectionError as ConnectionError, may I known why to do this?

Copy link
Collaborator

@Andrew-Chen-Wang Andrew-Chen-Wang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure to be honest; maybe to decrease imports? If anything, LGTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。
3 participants