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

fix resolve cancellation #2910

Merged
merged 16 commits into from
Apr 12, 2018

Conversation

thehesiod
Copy link
Contributor

@thehesiod thehesiod commented Apr 4, 2018

In my situation I have groups of 3 similar requests, where I take the fastest one out of the three and cancel the other two.

Lets say we have two groups of 3: A and B

B.1 succeeds
B.2 blocks on resolve (https://github.com/aio-libs/aiohttp/blob/master/aiohttp/connector.py#L702)

A.1 waits on resolve of B.2 (https://github.com/aio-libs/aiohttp/blob/master/aiohttp/connector.py#L689)

if we cancel B.2, it ends up cancelling A.1 because the exception is broadcast to all waiters: https://github.com/aio-libs/aiohttp/blob/master/aiohttp/locks.py#L31

so if a resolve is cancelled, only the task blocked on the resolve should be cancelled, not all the items waiting on the resolve. Only if it's a DNS error should the error be broadcast.

@codecov-io
Copy link

codecov-io commented Apr 4, 2018

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2910      +/-   ##
==========================================
+ Coverage   97.98%   97.98%   +<.01%     
==========================================
  Files          40       40              
  Lines        7506     7511       +5     
  Branches     1316     1318       +2     
==========================================
+ Hits         7355     7360       +5     
  Misses         48       48              
  Partials      103      103
Impacted Files Coverage Δ
aiohttp/connector.py 96.82% <100%> (ø) ⬆️
aiohttp/http_writer.py 100% <0%> (ø) ⬆️
aiohttp/http_exceptions.py 100% <0%> (ø) ⬆️
aiohttp/http_parser.py 98.05% <0%> (+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 2584ba2...1284612. Read the comment docs.

req.url.raw_host,
req.port,
traces=traces)
traces=traces))
Copy link
Member

Choose a reason for hiding this comment

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

Please pass loop=self._loop into shield().
Consider it as tiny speed optimization.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

# Cancelling this lookup should not cancel the underlying lookup
# or else the cancel event will get broadcast to all the waiters
# across all connections.
hosts = await asyncio.shield(self._resolve_host(
Copy link
Member

Choose a reason for hiding this comment

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

Is there two spaces between await and asyncio.shield()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@asvetlov
Copy link
Member

asvetlov commented Apr 5, 2018

Thank you for patch, looks almost good on the first glaze.
I need to review it more carefully, I hope to find a time for it in the evening.

# Cancelling this lookup should not cancel the underlying lookup
# or else the cancel event will get broadcast to all the waiters
# across all connections.
hosts = await asyncio.shield(self._resolve_host(
Copy link
Contributor

Choose a reason for hiding this comment

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

So this shield [1] can be removed, it was put in place just for the situation that you are commenting but taking a look at your MR - and the shield implementation - I was wrong.

[1] https://github.com/aio-libs/aiohttp/blob/master/aiohttp/connector.py#L702

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok was wondering about that, removed

@asvetlov
Copy link
Member

asvetlov commented Apr 8, 2018

The change looks good and reasonable but please add CHANGES file.
I'll merge and publish bugfix release than.

@thehesiod
Copy link
Contributor Author

@asvetlov added

@@ -0,0 +1 @@
fix cancellation broadcast during DNS resolve
Copy link
Member

Choose a reason for hiding this comment

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

I'm sorry but the folder name must be upper-cased: CHANGES/2910.bugfix.
The idea is having change-note on the top of changed files list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this folder was renamed in master, so I ran into this: https://coderwall.com/p/5w3jca/git-case-sensitivity-on-os-x fixed

@asvetlov
Copy link
Member

It was uppercased last in 2017, I don't remember the exact date.
The folder has .gitignore file, it always exists even if there are no feature files in CHANGES.

@asvetlov
Copy link
Member

LGTM.
@pfreixes please review.

@pfreixes pfreixes merged commit a7bbaad into aio-libs:master Apr 12, 2018
asvetlov pushed a commit that referenced this pull request Apr 12, 2018
* fix resolve cancellation

* fixes based on review

* changes based on review

* add changes file

* rename
(cherry picked from commit a7bbaad)

Co-authored-by: Alexander Mohr <thehesiod@users.noreply.github.com>
asvetlov added a commit that referenced this pull request Apr 12, 2018
* fix resolve cancellation

* fixes based on review

* changes based on review

* add changes file

* rename
(cherry picked from commit a7bbaad)

Co-authored-by: Alexander Mohr <thehesiod@users.noreply.github.com>
@thehesiod thehesiod deleted the thehesiod/resolve-fix branch April 13, 2018 19:28
@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.

4 participants