Skip to content
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

Raise cancelled on closed #2640

Merged
merged 5 commits into from
Jan 4, 2018
Merged

Raise cancelled on closed #2640

merged 5 commits into from
Jan 4, 2018

Conversation

azhpushkin
Copy link
Contributor

@azhpushkin azhpushkin commented Jan 3, 2018

What do these changes do?

Add raising of asyncio.CancelledError to PayloadWriter write() method to avoid writing to closing transport.

Are there changes in behavior for the user?

According to #2499 (comment) is was possible to catch this situation earlier by manually checking transport status of request. Thus, change should not broke any previously written code.

Related issue number

Resolves #2499

Checklist

  • [*] I think the code is well written
  • [*] Unit tests for the changes exist
  • [*] Add a new news fragment into the CHANGES folder

@codecov-io
Copy link

codecov-io commented Jan 3, 2018

Codecov Report

Merging #2640 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2640      +/-   ##
==========================================
+ Coverage   97.92%   97.92%   +<.01%     
==========================================
  Files          38       38              
  Lines        7265     7268       +3     
  Branches     1261     1262       +1     
==========================================
+ Hits         7114     7117       +3     
  Misses         47       47              
  Partials      104      104
Impacted Files Coverage Δ
aiohttp/http_writer.py 99.24% <100%> (+0.01%) ⬆️

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 b78228f...e4f3245. Read the comment docs.

pfreixes
pfreixes previously approved these changes Jan 3, 2018
@pfreixes
Copy link
Contributor

pfreixes commented Jan 3, 2018

LGTM changes approved, thanks!

@pfreixes pfreixes dismissed their stale review January 3, 2018 20:37

Branch out of date

@pfreixes
Copy link
Contributor

pfreixes commented Jan 3, 2018

but please first I would ask you to synchronize your branch with the master one.

@azhpushkin
Copy link
Contributor Author

@pfreixes Done! (i guess merge is enough for further rebase&squash? )

@pfreixes pfreixes merged commit 01113d3 into aio-libs:master Jan 4, 2018
@pfreixes
Copy link
Contributor

pfreixes commented Jan 4, 2018

thanks!

@asvetlov
Copy link
Member

asvetlov commented Jan 4, 2018

Hold on!
Is CancelledError raised by client API?
CancelledError without actual cancellation on resp.write() is confusing also.
I suggested raising RuntimeError or maybe even better a custom exception type derived from RuntimeError.

@azhpushkin
Copy link
Contributor Author

@asvetlov
Agree, make sence. But why RuntimeError and not ConnectionError, for example? It could be a good match.

@pfreixes
Copy link
Contributor

pfreixes commented Jan 4, 2018

Taking into account that write_eof calls the drain and it can have as a side effect a cancellation error if the client disconnects, don't we have to try to handle both cases in such a way that the developer can catch easily them using just one exception?

@pfreixes
Copy link
Contributor

pfreixes commented Jan 4, 2018

Yeps forgot my last comments, drain as other waiters are wake up with the proper exception once the connection gets closed. Should we use a ConnectionError [1] exception or one of its children?

[1] https://docs.python.org/3/library/exceptions.html#ConnectionError

@azhpushkin
Copy link
Contributor Author

asyncio's FlowControlMixin uses ConnectionResetError, so we could use it too, but I have a concern whether transport could be closed only on the other than aiohttp side (otherwise usual ConnectionError looks as a better match to me).

@davepallot
Copy link

How do you distinguish between a local task cancel and a remote socket disconnect? I have an app which needs to make that distinction.

@asvetlov
Copy link
Member

asvetlov commented Jun 1, 2018

No way right now.
But you didn't cancel a task -- something canceled it from outside :)

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bot:chronographer:provided There is a change note present in this PR outdated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Raise an exception if trying to write into closed response
5 participants