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 — [3.12] GH-106684: Close `asyncio.StreamWriter` when `asyncio.StreamWriter` is not closed by application (GH-107650) by miss-islington · Pull Request #107656 · python/cpython

Conversation

@miss-islington

@miss-islington miss-islington commented Aug 5, 2023 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

(cherry picked from commit 41178e4)

Co-authored-by: Kumar Aditya [email protected]

  • Issue: asyncio: potential leak of TLS connections #106684

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kumaraditya303 @miss-islington
pythonGH-106684: raise ResourceWarning when asyncio.StreamWriter …
385390a
…is not closed (pythonGH-107650)

(cherry picked from commit 41178e4)

Co-authored-by: Kumar Aditya <[email protected]>
@miss-islington
miss-islington requested review from 1st1, asvetlov, gvanrossum, kumaraditya303 and willingc as code owners August 5, 2023 12:18
This was referenced Aug 5, 2023
asyncio: potential leak of TLS connections #106684
Closed
GH-106684: raise ResourceWarning when StreamWriter is not closed #107650
Merged
@bedevere-bot bedevere-bot added type-bug An unexpected behavior, bug, or error awaiting review labels Aug 5, 2023
kumaraditya303
kumaraditya303 approved these changes Aug 5, 2023
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting review labels Aug 5, 2023
@kumaraditya303
kumaraditya303 requested a review from Yhg1s August 5, 2023 12:21
@Yhg1s
Yhg1s enabled auto-merge (squash) August 5, 2023 12:41
@Yhg1s
Yhg1s disabled auto-merge August 5, 2023 12:42
@Yhg1s

Yhg1s commented Aug 5, 2023

Copy link
Copy Markdown
Member

I think this should go into rc2, but without the warning. I think the warning is too potentially disruptive this late in the release cycle.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kumaraditya303
remove warning
02429ce
@kumaraditya303
kumaraditya303 force-pushed the backport-41178e4-3.12 branch from a16f262 to 02429ce Compare August 10, 2023 06:06
@kumaraditya303
remove test
f299eac
@kumaraditya303 kumaraditya303 changed the title [3.12] GH-106684: raise ResourceWarning when asyncio.StreamWriter is not closed (GH-107650) [3.12] GH-106684: Close asyncio.StreamWriter when asyncio.StreamWriter is not closed by application (GH-107650) Aug 10, 2023
@kumaraditya303 kumaraditya303 added the needs backport to 3.11 only security fixes label Aug 10, 2023
@kumaraditya303 kumaraditya303 assigned Yhg1s Aug 10, 2023
@Yhg1s
Yhg1s merged commit 7853c76 into python:3.12 Aug 10, 2023
@miss-islington

miss-islington commented Aug 10, 2023

Copy link
Copy Markdown
Contributor Author

Thanks @miss-islington for the PR, and @Yhg1s for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting merge label Aug 10, 2023
@miss-islington
miss-islington deleted the backport-41178e4-3.12 branch August 10, 2023 09:24
@bedevere-bot

bedevere-bot commented Aug 10, 2023

Copy link
Copy Markdown

GH-107836 is a backport of this pull request to the 3.11 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington added a commit to miss-islington/cpython that referenced this pull request Aug 10, 2023
@miss-islington @kumaraditya303
[3.12] pythonGH-106684: Close asyncio.StreamWriter when `asyncio.St…
91ce3ac
…reamWriter` is not closed by application (pythonGH-107650) (pythonGH-107656)

pythonGH-106684: raise `ResourceWarning` when `asyncio.StreamWriter` is not closed (pythonGH-107650)
(cherry picked from commit 41178e4)

(cherry picked from commit 7853c76)

Co-authored-by: Miss Islington (bot) <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>
@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Aug 10, 2023
kumaraditya303 added a commit that referenced this pull request Aug 10, 2023
@miss-islington @kumaraditya303
[3.11] [3.12] GH-106684: Close asyncio.StreamWriter when `asyncio.S…
fb08b79
…treamWriter` is not closed by application (GH-107650) (GH-107656) (#107836)

[3.12] GH-106684:  Close `asyncio.StreamWriter` when `asyncio.StreamWriter` is not closed by application (GH-107650) (GH-107656)

GH-106684: raise `ResourceWarning` when `asyncio.StreamWriter` is not closed (GH-107650)
(cherry picked from commit 41178e4)

(cherry picked from commit 7853c76)

Co-authored-by: Kumar Aditya <[email protected]>
@rigens

rigens commented Sep 12, 2023

Copy link
Copy Markdown

It seems that closing the connection in the StreamWriter's __del__ method is not a good idea. Consider the following use case

import asyncio

HOST = 'ifconfig.me'
PORT = 80


async def connect() -> asyncio.Transport:
    reader, writer = await asyncio.open_connection(
        host=HOST,
        port=PORT,
    )
    return writer.transport


async def fetch():
    loop = asyncio.get_running_loop()

    transport = await connect()
    # !!! transport is already closed here after this PR merged

    reader = asyncio.StreamReader(limit=2**16, loop=loop)
    protocol = asyncio.StreamReaderProtocol(reader, loop=loop)

    transport.set_protocol(protocol)
    loop.call_soon(protocol.connection_made, transport)
    loop.call_soon(transport.resume_reading)

    writer = asyncio.StreamWriter(
        transport=transport,
        protocol=protocol,
        reader=reader,
        loop=loop,
    )

    request = f'GET /ip HTTP/1.1\r\nHost: {HOST}\r\nConnection: close\r\n\r\n'.encode()
    writer.write(request)
    await writer.drain()

    response = await reader.read(-1)
    print(response)


if __name__ == '__main__':
    asyncio.run(fetch())
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rigens rigens mentioned this pull request Sep 13, 2023
asyncio: ConnectionResetError after StreamWriter is garbage collected #109321
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@kumaraditya303 kumaraditya303 kumaraditya303 approved these changes
@1st1 1st1 Awaiting requested review from 1st1 1st1 is a code owner
@asvetlov asvetlov Awaiting requested review from asvetlov asvetlov is a code owner
@gvanrossum gvanrossum Awaiting requested review from gvanrossum gvanrossum is a code owner
@willingc willingc Awaiting requested review from willingc willingc is a code owner
@Yhg1s Yhg1s Awaiting requested review from Yhg1s

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@Yhg1s Yhg1s

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@miss-islington @Yhg1s @bedevere-bot @rigens @kumaraditya303
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.