Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-29406: asyncio SSL contexts leak sockets after calling close with certain servers #409

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

Merged
merged 2 commits into from
Jun 10, 2017

Conversation

fafhrd91
Copy link
Contributor

@fafhrd91 fafhrd91 commented Mar 3, 2017

Some servers does not complete ssl shutdown procedure, which cause socket leak on asyncio side.

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA. This is necessary for legal reasons before we can look at your contribution. Please follow these steps to help rectify the issue:

  1. If you don't have an account on b.p.o, please create one
  2. Make sure your GitHub username is listed in "Your Details" at b.p.o
  3. If you have not already done so, please sign the PSF contributor agreement. The "bugs.python.org username " requested by the form is the "Login name" field under "Your Details".
  4. If you just signed the CLA, please wait at least one US business day and then check "Your Details" on bugs.python.org to see if your account has been marked as having signed the CLA (the delay is due to a person having to manually check your signed CLA)
  5. Reply here saying you have completed the above steps

Thanks again to your contribution and we look forward to looking at it!

@fafhrd91
Copy link
Contributor Author

fafhrd91 commented Mar 3, 2017

@1st1 PR for http://bugs.python.org/issue29406
I need to add tests though

@fafhrd91
Copy link
Contributor Author

fafhrd91 commented Mar 3, 2017

I actually signed CLA before I started to contribute to tulip/asyncio

@1st1
Copy link
Member

1st1 commented Mar 3, 2017

I actually signed CLA before I started to contribute to tulip/asyncio

I think you need to go to the bugs.python.org and add your GH username to your profile.

@fafhrd91
Copy link
Contributor Author

fafhrd91 commented Mar 3, 2017

I dont remembre account that I used when signed cla. I just re-signed it

@1st1
Copy link
Member

1st1 commented Mar 3, 2017

Maybe you used OAuth?

@fafhrd91
Copy link
Contributor Author

fafhrd91 commented Mar 3, 2017

my bugs.python.org details page shows "Contributor Form Received: Yes"

@1st1
Copy link
Member

1st1 commented Mar 3, 2017

Did you list your GH account name in your account on bpo?

@fafhrd91
Copy link
Contributor Author

fafhrd91 commented Mar 3, 2017

yes

@fafhrd91
Copy link
Contributor Author

fafhrd91 commented Mar 3, 2017

@fafhrd91 fafhrd91 changed the title asyncio SSL contexts leak sockets after calling close with certain servers bpo-29406: asyncio SSL contexts leak sockets after calling close with certain servers Mar 3, 2017
@1st1
Copy link
Member

1st1 commented Mar 3, 2017

@brettcannon something weird is going on here with @the-knights-who-say-ni bot.

@fafhrd91 Can you rebase your PR against master branch? And then add "needs backport to 3.6" and 3.5 tags.

@fafhrd91 fafhrd91 changed the base branch from 3.6 to master March 3, 2017 23:36
@fafhrd91
Copy link
Contributor Author

fafhrd91 commented Mar 3, 2017

rebased, but I can not add labels

self._shutdown_timeout_handle = self._loop.call_later(
self._shutdown_timeout, self._start_shutdown_timeout)

def _start_shutdown_timeout(self):
Copy link
Member

Choose a reason for hiding this comment

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

I would rename this method to _on_shutdown_timeout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

self._shutdown_timeout, self._start_shutdown_timeout)

def _start_shutdown_timeout(self):
if self._transport is not None:
Copy link
Member

Choose a reason for hiding this comment

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

To make the code more clear I would set self._transport = None in _finalize and _fatal_error methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@fafhrd91
Copy link
Contributor Author

fafhrd91 commented Mar 4, 2017

added simple unit tests

@brettcannon
Copy link
Member

@1st1 there was nothing weird going on; you didn't remove the "CLA not signed" to retrigger the bot to check for the new CLA signing. In the end the synchronizing of the PR triggered the bot again and picked up on the signing.


def _finalize(self):
if self._transport is not None:
self._transport.close()
self._transport = None
if self._shutdown_timeout_handle is not None:
Copy link
Member

Choose a reason for hiding this comment

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

little nit: I'd add a newline before this if.

@@ -412,7 +413,7 @@ class SSLProtocol(protocols.Protocol):

def __init__(self, loop, app_protocol, sslcontext, waiter,
server_side=False, server_hostname=None,
call_connection_made=True):
call_connection_made=True, shutdown_timeout=5.0):
Copy link
Member

Choose a reason for hiding this comment

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

Why is it 5 seconds? Is this some timeout value defined in some SSL RFC?

@1st1
Copy link
Member

1st1 commented Mar 12, 2017

@fafhrd91 ping

@fafhrd91
Copy link
Contributor Author

5 seconds just some number

@misg
Copy link

misg commented Apr 3, 2017

You may want to see #981

@fafhrd91
Copy link
Contributor Author

fafhrd91 commented Apr 3, 2017

@misg I think this is slightly different issue, #480 is related to #981

@misg
Copy link

misg commented Apr 3, 2017

@fafhrd91 I honestly don't know. In my case (with the server/client described in my PR), aiohttp.connector._cleanup_closed is always called and it is that function that calls asyncio.sslproto.SSLTransport._abort so I think I'm in the context where the ssl server doesn't complete ssh shutdown procedure (I actually didn't test with a ssl server that completes ssh shutdown procedure)

@1st1
Copy link
Member

1st1 commented Jun 9, 2017

@fafhrd91 Could you please rebase this PR on the most recent master? I'll merge it then.

@fafhrd91
Copy link
Contributor Author

fafhrd91 commented Jun 9, 2017

@1st1 done

@fafhrd91
Copy link
Contributor Author

fafhrd91 commented Jun 9, 2017

wait

@fafhrd91
Copy link
Contributor Author

fafhrd91 commented Jun 9, 2017

@1st1 restored

@1st1
Copy link
Member

1st1 commented Jun 9, 2017

Can you add a NEWS entry?

@fafhrd91
Copy link
Contributor Author

fafhrd91 commented Jun 9, 2017

added

@1st1 1st1 self-assigned this Jun 10, 2017
@1st1
Copy link
Member

1st1 commented Jun 10, 2017

@1st1 restored

unittests don't seem to pass :(

@@ -679,12 +692,18 @@ def _fatal_error(self, exc, message='Fatal error on transport'):
})
if self._transport:
self._transport._force_close(exc)
self._transport = None
Copy link
Member

Choose a reason for hiding this comment

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

Should we also cleanup _shutdown_timeout_handle here?

Copy link
Member

Choose a reason for hiding this comment

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

Should fatal_error just call finalize?

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 don't think that makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added cleanup code for _shutdown_timeout_handle, it is possible to get here while handle still active

@1st1 1st1 merged commit a608d2d into python:master Jun 10, 2017
1st1 pushed a commit that referenced this pull request Jun 10, 2017
1st1 added a commit that referenced this pull request Jun 10, 2017
…e with certain servers (GH-409)

* asyncio SSL contexts leak sockets after calling close with certain servers

* cleanup _shutdown_timeout_handle on _fatal_error.
(cherry picked from commit a608d2d)
1st1 pushed a commit that referenced this pull request Jun 10, 2017
1st1 added a commit that referenced this pull request Jun 10, 2017
…e with certain servers (GH-409)

* asyncio SSL contexts leak sockets after calling close with certain servers

* cleanup _shutdown_timeout_handle on _fatal_error.
(cherry picked from commit a608d2d)
1st1 added a commit that referenced this pull request Jun 10, 2017
…e with certain servers (GH-409) (#2062)

* bpo-29406: asyncio SSL contexts leak sockets after calling close with certain servers (#409)

(cherry picked from commit a608d2d)

* [3.6] bpo-29406: asyncio SSL contexts leak sockets after calling close with certain servers (GH-409)

* asyncio SSL contexts leak sockets after calling close with certain servers

* cleanup _shutdown_timeout_handle on _fatal_error.
(cherry picked from commit a608d2d)
1st1 added a commit that referenced this pull request Jun 10, 2017
…e with certain servers (GH-409) (#2063)

* bpo-29406: asyncio SSL contexts leak sockets after calling close with certain servers (#409)

(cherry picked from commit a608d2d)

* [3.5] bpo-29406: asyncio SSL contexts leak sockets after calling close with certain servers (GH-409)

* asyncio SSL contexts leak sockets after calling close with certain servers

* cleanup _shutdown_timeout_handle on _fatal_error.
(cherry picked from commit a608d2d)
1st1 added a commit that referenced this pull request Jun 11, 2017
1st1 added a commit that referenced this pull request Jun 11, 2017
…ing close with certain servers (GH-409) (#2062)"

This reverts commit 6e14fd2.
1st1 added a commit that referenced this pull request Jun 11, 2017
…ing close with certain servers (GH-409) (#2063)"

This reverts commit 1395c58.
1st1 added a commit that referenced this pull request Jun 11, 2017
…ing close with certain servers (GH-409) (#2062)" (#2112)

This reverts commit 6e14fd2.
1st1 added a commit that referenced this pull request Jun 11, 2017
…ing close with certain servers (GH-409) (#2063)" (#2113)

This reverts commit 1395c58.
1st1 added a commit that referenced this pull request Jun 11, 2017
jaraco pushed a commit that referenced this pull request Dec 2, 2022
Bumps [aiohttp](https://github.com/aio-libs/aiohttp) from 3.6.2 to 3.7.2.
- [Release notes](https://github.com/aio-libs/aiohttp/releases)
- [Changelog](https://github.com/aio-libs/aiohttp/blob/master/CHANGES.rst)
- [Commits](aio-libs/aiohttp@v3.6.2...v3.7.2)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants