httpcore icon indicating copy to clipboard operation
httpcore copied to clipboard

Handle async cancelled error explicitly

Open T-256 opened this issue 2 years ago • 6 comments

Summary

Discussed in https://github.com/encode/httpcore/discussions/805

Checklist

  • [x] I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • [ ] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • [ ] I've updated the documentation accordingly.

T-256 avatar Sep 19 '23 16:09 T-256

We'd need to change in both httpcore/_async and httpcore/_sync and ensure them match.

As what's said in #806, I think this could be ignored in unasync.py to avoid extra unuseful load. (Task behaviors not defined on threads.) But still I'm waiting to get proper response from team to choose final implementation for sync part.

T-256 avatar Sep 20 '23 11:09 T-256

Is this solution respects such cases?

because the user may catch the keyboardinterrupt in his code and continue to use httpcore.ConnectionPool.

karpetrosyan avatar Sep 20 '23 11:09 karpetrosyan

Is this solution respects such cases?

No, #812 will respect.

Actually this PR can expose why current cleanup system is not well implemented.

T-256 avatar Sep 20 '23 11:09 T-256

No, #812 will respect.

Do we want to marge this PR when we know it will break programs that handle BaseExceptions like KeyboardInterrupt?

karpetrosyan avatar Sep 20 '23 11:09 karpetrosyan

Do we want to marge this PR when we know it will break programs that handle BaseExceptions like KeyboardInterrupt?

Yes. because still some of cleanups doesn't handle BaseException in codebase:

  • https://github.com/encode/httpcore/blob/94ffb33cf378e41662c90615458db9e42b43cad5/httpcore/_async/connection.py#L97-L100

  • https://github.com/encode/httpcore/blob/94ffb33cf378e41662c90615458db9e42b43cad5/httpcore/_async/http2.py#L441-L453

  • https://github.com/encode/httpcore/blob/94ffb33cf378e41662c90615458db9e42b43cad5/httpcore/_async/http2.py#L470-L482

  • https://github.com/encode/httpcore/blob/94ffb33cf378e41662c90615458db9e42b43cad5/httpcore/_async/socks_proxy.py#L294-L297

  • https://github.com/encode/httpcore/blob/94ffb33cf378e41662c90615458db9e42b43cad5/httpcore/_backends/anyio.py#L76-L79

  • https://github.com/encode/httpcore/blob/94ffb33cf378e41662c90615458db9e42b43cad5/httpcore/_backends/trio.py#L78-L81

  • plus, same things in _sync part.

And also notice few BaseException was introduced in https://github.com/encode/httpcore/pull/726, so before that we were not supporting KeyboardInterrupt:

  • First, Before: no error handling, After: BaseException handling.
  • Second, Before: Exception handling, After: BaseException handling.

T-256 avatar Sep 20 '23 13:09 T-256

Should we consider convert exception handlings in https://github.com/encode/httpcore/pull/811#issuecomment-1727720109 to EXCEPTION_OR_CANCELLED?

T-256 avatar Sep 20 '23 14:09 T-256

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 26 '25 04:04 stale[bot]