GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Task created by StreamReaderProtocol gets garbage collected. · Issue #90467 · python/cpython

Task created by StreamReaderProtocol gets garbage collected. #90467

New issue
Copy link
New issue
Copy link
Closed
Closed
Task created by StreamReaderProtocol gets garbage collected.#90467
Copy link
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.9 (EOL)end of lifeend of lifetopic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

simwr872
mannequin
opened on Jan 8, 2022
Issue body actions
BPO 46309
Nosy @asvetlov, @1st1, @kumaraditya303, @simwr872
PRs
  • bpo-46309: Added reference to task created by StreamReaderProtocol #30505
  • Files
  • example.py
  • 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 2022-01-08.23:35:55.417>
    labels = ['3.11', 'type-bug', '3.9', '3.10', 'expert-asyncio']
    title = 'Task created by StreamReaderProtocol gets garbage collected.'
    updated_at = <Date 2022-01-11.15:54:38.380>
    user = 'https://github.com/simwr872'

    bugs.python.org fields:

    activity = <Date 2022-01-11.15:54:38.380>
    actor = 'AlexWaygood'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['asyncio']
    creation = <Date 2022-01-08.23:35:55.417>
    creator = 'simwr872'
    dependencies = []
    files = ['50552']
    hgrepos = []
    issue_num = 46309
    keywords = ['patch']
    message_count = 3.0
    messages = ['410124', '410134', '410310']
    nosy_count = 4.0
    nosy_names = ['asvetlov', 'yselivanov', 'kumaraditya', 'simwr872']
    pr_nums = ['30505']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46309'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    Activity

    Next
    1. simwr872 commented on Jan 8, 2022

      @simwr872
      simwr872mannequin
      on Jan 8, 2022
      MannequinAuthor
      More actions

      Documentation states that a reference must be kept when creating a task, https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task.

      This is not done in StreamReaderProtocol, https://github.com/python/cpython/blob/main/Lib/asyncio/streams.py#L244.

      I've provided a simple example to force garbage collection of this task which results in Task was destroyed but it is pending!. Uncommenting the commented code of the example shows that the task is not destroyed when a reference is kept.

      Am I missing something or using the library incorrectly? I've followed the examples at https://docs.python.org/3/library/asyncio-stream.html#tcp-echo-server-using-streams.

    2. simwr872
      added
      3.10 (EOL)end of lifeend of life
      topic-asyncio
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Jan 8, 2022
    3. asvetlov commented on Jan 9, 2022

      @asvetlov
      asvetlov
      on Jan 9, 2022
      Contributor
      More actions

      Thanks for the bug report.

      Seems like your analysis is correct.

      Could you make a pull request which adds a task reference?

    4. simwr872
      added
      3.7 (EOL)end of lifeend of life
      3.8 (EOL)end of lifeend of life
      3.9 (EOL)end of lifeend of life
      3.11only security fixesonly security fixes
      on Jan 11, 2022
    5. 3 remaining items

    6. AlexWaygood
      removed
      3.8 (EOL)end of lifeend of life
      3.7 (EOL)end of lifeend of life
      on Jan 11, 2022
    7. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    8. ezio-melotti
      added this to asyncioon Jul 17, 2022
    9. ezio-melotti
      moved this to Todo in asyncioon Jul 17, 2022
    10. python273 commented on Aug 26, 2022

      @python273
      python273
      on Aug 26, 2022
      Contributor
      More actions

      As a workaround, it's possible to keep the reference in a global variable

      background_tasks = set()
      def create_connection_task(*args, **kwargs):
          task = asyncio.create_task(handle_connection(*args, **kwargs))
          background_tasks.add(task)
          task.add_done_callback(background_tasks.discard)
      
      # asyncio.start_server(create_connection_task, ..)
    11. python273
      added a commit that references this issue on Aug 26, 2022

      pythongh-90467: StreamReaderProtocol - add strong reference to create…

      91c8678
    12. miss-islington
      added 2 commits that reference this issue on Aug 27, 2022

      pythongh-90467: StreamReaderProtocol - add strong reference to create…

      c98a665

      pythongh-90467: StreamReaderProtocol - add strong reference to create…

      63a903b
    13. gvanrossum
      added a commit that references this issue on Aug 27, 2022

      gh-90467: StreamReaderProtocol - add strong reference to created task (…

      e860e52
    14. pablogsal
      added a commit that references this issue on Aug 30, 2022

      gh-90467: StreamReaderProtocol - add strong reference to created task (…

      126ec34
    15. miss-islington
      added a commit that references this issue on Sep 8, 2022

      gh-90467: StreamReaderProtocol - add strong reference to created task (…

      280130f
    16. kumaraditya303
      closed this as completedon Sep 9, 2022
    17. Repository owner moved this from Todo to Done in asyncioon Sep 9, 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.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.9 (EOL)end of lifeend of lifetopic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

      Projects

      • asyncio
        Status
        Done
        Show more project fields

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.