Skip to content

asyncio sslproto do not shutdown ssl layer cleanly #74883

Closed

Description

@grzgrzgrz3
BPO 30698
Nosy @asvetlov, @1st1, @legnaleurc, @thehesiod, @grzgrzgrz3, @Zheaoli, @kumaraditya303
PRs
  • bpo-30698: asyncio shutdown the ssl layer cleanly. #2270
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2022-02-28.11:36:37.270>
    created_at = <Date 2017-06-18.22:08:35.057>
    labels = ['3.11', 'type-bug', 'expert-asyncio']
    title = 'asyncio sslproto do not shutdown ssl layer cleanly'
    updated_at = <Date 2022-02-28.11:36:37.269>
    user = 'https://github.com/grzgrzgrz3'

    bugs.python.org fields:

    activity = <Date 2022-02-28.11:36:37.269>
    actor = 'asvetlov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-02-28.11:36:37.270>
    closer = 'asvetlov'
    components = ['asyncio']
    creation = <Date 2017-06-18.22:08:35.057>
    creator = 'grzgrzgrz3'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30698
    keywords = []
    message_count = 9.0
    messages = ['296295', '296531', '309821', '309826', '317704', '327745', '332364', '414181', '414187']
    nosy_count = 7.0
    nosy_names = ['asvetlov', 'yselivanov', 'legnaleurc', 'thehesiod', 'grzgrzgrz3', 'Manjusaka', 'kumaraditya']
    pr_nums = ['2270']
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue30698'
    versions = ['Python 3.11']

    Activity

    1. grzgrzgrz3 commented on Jun 18, 2017

      grzgrzgrz3mannequin
      MannequinAuthor

      Asyncio on shutdown do not send shutdown confirmation to the other side. _SSLPipe after doing unwrap is calling shutdown callback where transport is closed and quit ssldata wont be sent.

    2. added
      3.7 (EOL)
      type-bug
      on Jun 18, 2017
    3. grzgrzgrz3 commented on Jun 21, 2017

      grzgrzgrz3mannequin
      MannequinAuthor

      No one yet responded, maybe this is unclear. I will clarify what is going on, why i made this change, what we gain from this and why this is not ideal solution.

      I will focus on ssl layer shutdown as this issue regards.

      We have connection asyncio <-> nginx

      Lets see first situation asyncio initiates shutdown:

      1. ideal:

            shutdown
        

      asyncio ----------> nginx
      <----------
      shutdown
      Ideal situation asyncio sending shutdown and nginx replies back. This is how it works before attached PR.

      1. we can't relay on nginx

            shutdown
        

      asyncio ----------> nginx
      |||||||||||
      shutdown

      At this point everything looks great, but what will happen when nginx do not sent shutdown - we will wait forever.
      We have this situation here bpo-29406.

      Attached PR "fix" this problem (note is not ideal fix, more like workaround):

      1. with fix:

            shutdown
        

      asyncio ----------> nginx
      ||?--------
      shutdown
      asyncio is sending shutdown ssl data to nginx but not waiting for nginx response, transport is closed anyway. I think ideal will
      be to wait for certain amount of time for response like Nikolay in bpo-29406 propose. This will allow to implement SSL downgrade to
      plain text.

      Second situation, nginx sent ssl eof.

      1. before fix:
        shutdown
        nginx ----------> asyncio
        |||||||||||
        shutdown
        In this case we are receiving nginx shutdown and correctly process it but after that, shutdown callback will close the transport before
        shutdown is sent back. Asyncio will try to send this data but fail due to closed transport. There is another issue should be not possible
        to write to closed transport. We are getting false-positive result to write. I do not analyze this deeper,
        maybe there is a reason to it.

      2. after fix:
        shutdown
        nginx ----------> asyncio
        <----------
        shutdown

      This is clean, shutdown callback in _SSLPipe is removed. We close transport in ssl protocol.

      I think connections between _SSLPipe and ssl protocol has design problems, _SSLPipe should be, as name suggest, only a pipe.
      Callback for handshake and shutdown feels wrong. Ssl protocol based on _SSLPipie mode and state can figure out when to call
      connection_made or close transport.

    4. thehesiod commented on Jan 11, 2018

      thehesiodmannequin
      Mannequin

      @grzgrzgrz3, does this resolve the issue in https://bugs.python.org/issue29406 ? I'm guessing you based this PR on that issue. If so I'd like it merged ASAP as otherwise our prod services will be incompatible with all future python releases given the original "fix" was reverted. Thanks!

    5. grzgrzgrz3 commented on Jan 11, 2018

      grzgrzgrz3mannequin
      MannequinAuthor

      No, this PR originally fix similar but different issue.

      However it also fix bpo-29406 as a side effect.

    6. 1st1 commented on May 25, 2018

      @1st1
      Member

      Is this issue resolved now, or do we need to work on this?

    7. legnaleurc commented on Oct 15, 2018

      legnaleurcmannequin
      Mannequin

      The SSL connection still cannot close cleanly in 3.7.0.
      It will keep throwing read error during shutdown, so shutdown callback will never be called.

      I've been test this PR for a while, and at least it fixes my problem.

      Hope this PR can be included in 3.7.1, or at least 3.7.2.

    8. Zheaoli commented on Dec 22, 2018

      Zheaolimannequin
      Mannequin

      Ping!

      Agree with Wei-Cheng.

      The leak still bothers me for times, and still bother for third-party like https://aiohttp.readthedocs.io/en/stable/client_reference.html#tcpconnector

      Yury, I think it's worth working on it. Using uvloop should not be a good idea for some people.

    9. kumaraditya303 commented on Feb 28, 2022

      @kumaraditya303
      Contributor
    10. added
      3.11
      and removed
      3.7 (EOL)
      on Feb 28, 2022
    11. asvetlov commented on Feb 28, 2022

      @asvetlov
      Contributor

      Agree

    12. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.11topic-asynciotype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions