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 — Calling SelectorSocketTransport.writelines with a very large payload doesn't get completely written to the socket · Issue #103462 · python/cpython

Calling SelectorSocketTransport.writelines with a very large payload doesn't get completely written to the socket #103462

New issue
Copy link
New issue
Copy link
Closed
#103463
Closed
Calling SelectorSocketTransport.writelines with a very large payload doesn't get completely written to the socket#103462
#103463
Copy link
Assignees
kumaraditya303
Labels
3.12only security fixesonly security fixestopic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@alisaifee
alisaifee
opened on Apr 12, 2023
Issue body actions

Bug report

As a consequence of the optimization introduced in #91166, when SelectorSocketTransport.writelines is used with a very large buffer which can't be written in one shot either by using socket.send or socket.sendmsg the remaining data in the buffer is never written to the socket.

The following example can be used to reproduce the error:

import asyncio


async def send_message(chunk_size: int, chunks: int):
    await asyncio.sleep(1)
    reader, writer = await asyncio.open_connection("127.0.0.1", 9898)
    data = [bytes(chunk_size)] * chunks + [b"end"]
    writer.writelines(data)
    await writer.drain()
    writer.close()
    await writer.wait_closed()


async def handle_message(reader, writer):
    data = await reader.read()
    print(f"End marker: {data[-3:]!r}")
    writer.close()
    await writer.wait_closed()


async def run_server():
    server = await asyncio.start_server(handle_message, "127.0.0.1", 9898)
    async with server:
        await server.serve_forever()


async def main():
    await asyncio.gather(run_server(), send_message(6500, 100))


asyncio.run(main())

The example above prints End marker: b'end' with python 3.11 but not with python 3.12.0a6+

Your environment

  • CPython versions tested on: 3.12.0a7
  • Operating system and architecture: macOS 13.2

Linked PRs

  • gh-103462: Ensure SelectorSocketTransport.writelines registers a writer when data is still pending #103463

Activity

  1. alisaifee
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Apr 12, 2023
  2. kumaraditya303 commented on Apr 12, 2023

    @kumaraditya303
    kumaraditya303
    on Apr 12, 2023
    Contributor
    More actions

    Good catch! I have been running this code for a while but the buffers aren't large enough to trigger this.

  3. kumaraditya303
    added
    topic-asyncio
    3.12only security fixesonly security fixes
    on Apr 12, 2023
  4. kumaraditya303
    self-assigned this
    on Apr 12, 2023
  5. ezio-melotti
    added this to asyncioon Apr 12, 2023
  6. github-project-automation
    moved this to Todo in asyncioon Apr 12, 2023
  7. kumaraditya303
    linked a pull request that will close this issuegh-103462: Ensure SelectorSocketTransport.writelines registers a writer when data is still pending #103463on Apr 13, 2023
  8. kumaraditya303
    closed this as completedin #103463on Apr 13, 2023
  9. github-project-automation
    moved this from Todo to Done in asyncioon Apr 13, 2023
  10. kumaraditya303
    added a commit that references this issue on Apr 13, 2023

    gh-103462: Ensure SelectorSocketTransport.writelines registers a writ…

    19d2639
  11. carljm
    added a commit that references this issue on Apr 13, 2023

    Merge branch 'main' into superopt

    9384106
  12. aisk
    added a commit that references this issue on Apr 18, 2023

    pythongh-103462: Ensure SelectorSocketTransport.writelines registers …

    44b69f6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @kumaraditya303
    kumaraditya303

Labels

3.12only security fixesonly security fixestopic-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.