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

Close unclosed client sessions properly #2523

Merged
merged 6 commits into from Nov 17, 2017

Conversation

Projects
None yet
3 participants
@hynek
Contributor

hynek commented Nov 16, 2017

What do these changes do?

ClientSession.__del__ uses a bare self.close() which causes a warning. This fixes that warning. I think this should be fine like that?

Are there changes in behavior for the user?

One warning less.

Related issue number

n/a

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • 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.
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> for example (588.bug)
    • 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."

hynek added some commits Nov 16, 2017

@asvetlov

This comment has been minimized.

Member

asvetlov commented Nov 16, 2017

It's a complex question.
__del__ is called on session destruction.
It could be even interpreter finalization stage if the session has global scope (we discourage this approach but still support it).

If the loop is closed before ClientSession.__del__ -- nothing to do.

On other hand the session could be dropped in coroutine context:

async def f():
    session = aiohttp.ClientSession()
    ...
    del session  # or just implicit decref on frame destruction

In this case the loop is running, loop.run_until_complete() is prohibited.

@hynek

This comment has been minimized.

Contributor

hynek commented Nov 16, 2017

Yeah, I suspected it’s not clear cut.

I’d suggest to either drop the close altogether or wrap it in a with suppress(Exception): for an best-effort try. As it’s now it’s kind useless, isn’t it?

@asvetlov

This comment has been minimized.

Member

asvetlov commented Nov 16, 2017

I think dropping is just fine.
Let's keep a warning report part but don't try to close the session: it is not very reliable.

hynek added some commits Nov 16, 2017

@codecov-io

This comment has been minimized.

codecov-io commented Nov 16, 2017

Codecov Report

Merging #2523 into master will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2523      +/-   ##
==========================================
- Coverage   97.13%   97.13%   -0.01%     
==========================================
  Files          39       39              
  Lines        8066     8065       -1     
  Branches     1414     1414              
==========================================
- Hits         7835     7834       -1     
  Misses         99       99              
  Partials      132      132
Impacted Files Coverage Δ
tests/autobahn/client.py 94.91% <0%> (-0.02%) ⬇️

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 48a704d...d573a63. Read the comment docs.

@asvetlov asvetlov changed the base branch from master to 2.3 Nov 16, 2017

@asvetlov asvetlov changed the base branch from 2.3 to master Nov 16, 2017

@asvetlov asvetlov merged commit d6426ad into aio-libs:master Nov 17, 2017

3 checks passed

codecov/patch Coverage not affected when comparing 48a704d...d573a63
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

asvetlov added a commit that referenced this pull request Nov 17, 2017

Close unclosed client sessions properly (#2523)
* Close unclosed client sessions properly

* Add news fragment

* Drop it all together
@asvetlov

This comment has been minimized.

Member

asvetlov commented Nov 17, 2017

Thanks!
Backported to 2.3, aiohttp 2.3.3 released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment