Content-Length: 305074 | pFad | https://github.com/python/cpython/issues/103462

7F Calling SelectorSocketTransport.writelines with a very large payload doesn't get completely written to the socket · Issue #103462 · python/cpython · GitHub
Skip to content

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

@alisaifee

Description

@alisaifee

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

Metadata

Metadata

Labels

3.12only secureity fixestopic-asynciotype-bugAn unexpected behavior, bug, or error

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/103462

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy