From d2825af045dfecc69b6041d1a6b3a1469f0f6890 Mon Sep 17 00:00:00 2001 From: varunrmallya <100590632+varun-r-mallya@users.noreply.github.com> Date: Tue, 10 Jun 2025 23:14:07 +0530 Subject: [PATCH] fix(examples/echo/echo.py): Add max message length to stream.read (#671) Signed-off-by: varun-r-mallya --- examples/echo/echo.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/echo/echo.py b/examples/echo/echo.py index 535133fa..9f1722b2 100644 --- a/examples/echo/echo.py +++ b/examples/echo/echo.py @@ -20,11 +20,12 @@ from libp2p.peer.peerinfo import ( ) PROTOCOL_ID = TProtocol("/echo/1.0.0") +MAX_READ_LEN = 2**32 - 1 async def _echo_stream_handler(stream: INetStream) -> None: # Wait until EOF - msg = await stream.read() + msg = await stream.read(MAX_READ_LEN) await stream.write(msg) await stream.close() @@ -72,10 +73,8 @@ async def run(port: int, destination: str, seed: int | None = None) -> None: msg = b"hi, there!\n" await stream.write(msg) - # TODO: check why the stream is closed after the first write ??? - # Notify the other side about EOF - await stream.close() response = await stream.read() + await stream.close() print(f"Sent: {msg.decode('utf-8')}") print(f"Got: {response.decode('utf-8')}")