Skip to content

StreamWriter.wait_closed() can hang indefinitely. #83939

Closed

Description

@tomchristie
BPO 39758
Nosy @warsaw, @bitdancer, @asvetlov, @tomchristie, @1st1, @JulienPalard, @lysnikolaou, @aeros, @r-owen, @kumaraditya303

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 = None
created_at = <Date 2020-02-26.10:36:06.728>
labels = ['3.11', 'type-bug', 'expert-asyncio']
title = 'StreamWriter.wait_closed() can hang indefinitely.'
updated_at = <Date 2022-03-03.11:14:26.540>
user = 'https://github.com/tomchristie'

bugs.python.org fields:

activity = <Date 2022-03-03.11:14:26.540>
actor = 'kumaraditya'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['asyncio']
creation = <Date 2020-02-26.10:36:06.728>
creator = 'tomchristie'
dependencies = []
files = []
hgrepos = []
issue_num = 39758
keywords = []
message_count = 6.0
messages = ['362688', '362738', '387644', '387645', '400863', '414423']
nosy_count = 12.0
nosy_names = ['barry', 'r.david.murray', 'asvetlov', 'tomchristie', 'yselivanov', 'mdk', 'lys.nikolaou', 'aeros', 'Fran\xc3\xa7ois Voron', 'r3owen', 'kumaraditya', 'seer']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue39758'
versions = ['Python 3.11']

Activity

  1. tomchristie commented on Feb 26, 2020

    tomchristiemannequin
    MannequinAuthor

    Raising an issue that's impacting us on httpx.

    It appears that in some cases SSL unwrapping can cause .wait_closed() to hang indefinately.

    Trio are particularly careful to work around this case, and have an extensive comment on it: https://github.com/python-trio/trio/blob/31e2ae866ad549f1927d45ce073d4f0ea9f12419/trio/_ssl.py#L779-L829

    Originally raised via encode/httpx#634

    Tested on:

    • Python 3.7.6
    • Python 3.8.1
    import asyncio
    import ssl
    import certifi
    
    hostname = 'login.microsoftonline.com'
    context = ssl.create_default_context()
    context.load_verify_locations(cafile=certifi.where())
    
    async def main():
        reader, writer = await asyncio.open_connection(hostname, 443, ssl=context)
        print('opened')
        writer.close()
        print('close started')
        await writer.wait_closed()
        print('close completed')
    
    asyncio.run(main())
    
  2. added
    type-bug
    3.7 (EOL)
    3.8 (EOL)
    on Feb 26, 2020
  3. changed the title [-]StreamWriter.wait_closed() can hang indefinately.[/-] [+]StreamWriter.wait_closed() can hang indefinitely.[/+] on Feb 26, 2020
  4. JulienPalard commented on Feb 26, 2020

    @JulienPalard
    Member

    Can reproduce in:

    • 3.8.0
    • 3.8.2
    • 3.7.6
  5. r-owen commented on Feb 25, 2021

    r-owenmannequin
    Mannequin

    I am also seeing this in Python 3.8.6. I am not using SSL, but am simply calling await writer.wait_closed() on an asyncio.StreamWriter. Sometimes it works quickly and sometimes it hangs indefinitely.

  6. r-owen commented on Feb 25, 2021

    r-owenmannequin
    Mannequin

    Regarding my previous comment: I have never seen this in Python 3.7 (though I see that this particular bug is listed as being present there) so it may be a different underlying issue.

  7. seer commented on Sep 1, 2021

    seermannequin
    Mannequin

    See this issue on 3.9.6
    No SSL, but plain sockets.
    This seems to appear when writer.write/writer.drain was cancelled, and writer.close/writer.wait_closed called after this.

  8. added
    3.9 (EOL)
    on Sep 1, 2021
  9. added
    build
    tests
    on Sep 1, 2021
  10. 4 remaining items

  11. added
    performance
    and removed
    type-bug
    on Sep 1, 2021
  12. removed
    build
    tests
    interpreter-core
    on Sep 1, 2021
  13. kumaraditya303 commented on Mar 3, 2022

    @kumaraditya303
    Contributor

    On main branch with rewritten SSL implementation #75458 bpo-44011, this raises TimeoutError:

    --------------------------------------------------------------------------------
    opened
    close started

    Traceback (most recent call last):
      File "/workspaces/cpython/main.py", line 18, in <module>
        asyncio.run(main())
        ^^^^^^^^^^^^^^^^^^^
      File "/workspaces/cpython/Lib/asyncio/runners.py", line 44, in run
        return loop.run_until_complete(main)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/workspaces/cpython/Lib/asyncio/base_events.py", line 645, in run_until_complete
        return future.result()
               ^^^^^^^^^^^^^^^
      File "/workspaces/cpython/main.py", line 14, in main
        await writer.wait_closed()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/workspaces/cpython/Lib/asyncio/streams.py", line 344, in wait_closed
        await self._protocol._get_close_waiter(self)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    TimeoutError: SSL shutdown timed out

    This issue has been fixed, it can be closed @asvetlov.

  14. added
    type-bug
    and removed
    3.8 (EOL)
    3.9 (EOL)
    3.10 (EOL)
    performance
    on Mar 3, 2022
  15. 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