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

Fixing issue #7072 #7608

Closed
wants to merge 2 commits into from
Closed

Fixing issue #7072 #7608

wants to merge 2 commits into from

Conversation

cnicodeme
Copy link

@cnicodeme cnicodeme commented Sep 14, 2023

Under some specific circumstances, _resolve_host can fail, which will lead to an exception Task was destroyed but it is pending!.

This PR fixes the issue.

What do these changes do?

Following suggestion from @michaelzus, applying host_resolved.cancel() when a CancelledError occurs stop the above issue to be raised.

Are there changes in behavior for the user?

None

Related issue number

Fixes #7072

Checklist

  • [x ] I think the code is well written
  • Unit tests for the changes exist
  • [ x] Documentation reflects the changes
  • [ x] If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • [x ] Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Sep 14, 2023
@codecov
Copy link

codecov bot commented Sep 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.35%. Comparing base (b6afdc3) to head (7c48398).
Report is 2149 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7608      +/-   ##
==========================================
- Coverage   97.35%   97.35%   -0.01%     
==========================================
  Files         106      106              
  Lines       31513    31514       +1     
  Branches     3589     3589              
==========================================
  Hits        30679    30679              
- Misses        630      631       +1     
  Partials      204      204              
Flag Coverage Δ
CI-GHA 97.27% <100.00%> (-0.01%) ⬇️
OS-Linux 96.94% <100.00%> (-0.01%) ⬇️
OS-Windows 95.40% <100.00%> (-0.01%) ⬇️
OS-macOS 96.60% <100.00%> (-0.01%) ⬇️
Py-3.10.11 95.33% <100.00%> (-0.01%) ⬇️
Py-3.10.13 96.81% <100.00%> (-0.01%) ⬇️
Py-3.11.5 96.51% <100.00%> (-0.01%) ⬇️
Py-3.8.10 95.30% <100.00%> (-0.01%) ⬇️
Py-3.8.18 96.74% <100.00%> (-0.01%) ⬇️
Py-3.9.13 95.29% <100.00%> (-0.01%) ⬇️
Py-3.9.18 96.77% <100.00%> (-0.01%) ⬇️
Py-pypy7.3.11 96.30% <100.00%> (-0.01%) ⬇️
VM-macos 96.60% <100.00%> (-0.01%) ⬇️
VM-ubuntu 96.94% <100.00%> (-0.01%) ⬇️
VM-windows 95.40% <100.00%> (-0.01%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Dreamsorcerer
Copy link
Member

Thanks, do you think you could turn your reproducer into a test?

@cnicodeme
Copy link
Author

No I'm sorry I don't know how to do that.

@Dreamsorcerer
Copy link
Member

It looks like your reproducer just mocks out a method before making a request. You can mock it out properly in a test with mock.patch(). You can add a with pytest.warns() to catch any warnings and assert there are none.

@@ -0,0 +1 @@
Fixes the "Task was destroyed but it is pending" issue related to `TCPConnector._resolve_host` taking too long (probably because of a DNS lookup failure)
Copy link
Member

Choose a reason for hiding this comment

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

Additionally to what Sam asked regarding adding a regression test, this change note must use RST syntax (hence double backticks, not single). And please, check out https://docs.aiohttp.org/en/stable/contributing.html#adding-change-notes-with-your-prs for the writing style to be used in the changelog. For example, in order for it to be coherent, the past tense should be used (or variants of the present tense referring to the changes as compared to the previous release).
You can also optionally add a byline. It's all described in that document.

@@ -1107,6 +1107,7 @@ def drop_exception(fut: "asyncio.Future[List[Dict[str, Any]]]") -> None:
fut.result()

host_resolved.add_done_callback(drop_exception)
host_resolved.cancel()
Copy link
Member

Choose a reason for hiding this comment

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

Looking at this again, the comment above very clearly says we shouldn't cancel this task, which is why it's shielded. Without a test, I don't think this will be going anywhere.

@Dreamsorcerer Dreamsorcerer added the pr-unfinished The PR is unfinished and may need a volunteer to complete it label Sep 1, 2024
@Dreamsorcerer
Copy link
Member

Superseded by #8967.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR pr-unfinished The PR is unfinished and may need a volunteer to complete it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Task was destroyed but it is pending! timeout
3 participants