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
Fix response not closed when read stream canceled #2148
Conversation
098c8d6
to
3ed42c0
Compare
@@ -933,7 +933,7 @@ def _send_handling_auth( | |||
request = next_request | |||
history.append(response) | |||
|
|||
except Exception as exc: | |||
except BaseException as exc: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe catch Exception
and asyncio.exceptions.CancelledError
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we need catch all exceptions to ensure response closed, just like async with
context manager. And the exception will re-raised so it will not swallow errors.
Great thank you. Yup, I'm in favour of switching over to I'm not keen on us having test cases that introduce sleeps, tho. Perhaps we could change those around somehow. |
In Python 3.6, asyncio.wait_for will not cancel the task, so I skip the test in py36. https://stackoverflow.com/questions/69370252/asyncio-wait-for-didnt-cancel-the-task |
I think we should move the |
Hi @florimondmanca Seems the response not always need close, eg stream request: https://github.com/encode/httpx/blob/master/httpx/_client.py#L904 . |
@tomchristie 👍👍 your test case is perfect! |
Thanks folks. Closing this in favour of #2156. We also ought to address any similar cases in |
See #2139 (comment), the PR only fix issues of httpx client.