Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

StreamReader.read(-1) cannot receive data before the write end is closed #251

@wangst321

Description

@wangst321

Echo client

import asyncio

loop = asyncio.get_event_loop()
coro = asyncio.open_connection('127.0.0.1', 4001)
reader, writer = loop.run_until_complete(coro)
writer.write(b'hello')
writer.write_eof()

# bug: it just return and cannot get echo_msg
msg = loop.run_until_complete(reader.read(-1))
print(msg)

Echo server

import asyncio

@asyncio.coroutine
def process_request(reader, writer):
    peername = writer.get_extra_info("peername")
    msg = yield from reader.read(-1)
    print(peername, msg)
    writer.write(msg)
    writer.write_eof()

loop = asyncio.get_event_loop()
coro = asyncio.start_server(process_request, host='127.0.0.1', port=4001)
server = loop.run_until_complete(coro)

try:
    loop.run_forever()
finally:
    loop.stop()

Run the server, then run the client. The client should get

b'hello'

but, it got

b''

the client didn't wait for the write end close.

msg = loop.run_until_complete(reader.read(-1))   # not work

My python version is

python3.4.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions