From 1721f078c725bc566f21a2fed2655c216b9ae075 Mon Sep 17 00:00:00 2001 From: Tanguy Date: Mon, 10 Jul 2023 15:52:08 +0200 Subject: [PATCH] Fix crash on empty write (#930) --- libp2p/stream/chronosstream.nim | 4 +++- tests/commontransport.nim | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libp2p/stream/chronosstream.nim b/libp2p/stream/chronosstream.nim index b5f365875..b93d46f8d 100644 --- a/libp2p/stream/chronosstream.nim +++ b/libp2p/stream/chronosstream.nim @@ -129,7 +129,9 @@ method write*(s: ChronosStream, msg: seq[byte]): Future[void] = # drives up memory usage if msg.len == 0: trace "Empty byte seq, nothing to write" - return + let fut = newFuture[void]("chronosstream.write.empty") + fut.complete() + return fut if s.closed: let fut = newFuture[void]("chronosstream.write.closed") fut.fail(newLPStreamClosedError()) diff --git a/tests/commontransport.nim b/tests/commontransport.nim index 419e857bb..7f1b5f361 100644 --- a/tests/commontransport.nim +++ b/tests/commontransport.nim @@ -150,6 +150,7 @@ template commonTransportTest*(prov: TransportProvider, ma1: string, ma2: string proc acceptHandler() {.async, gcsafe.} = while true: let conn = await transport1.accept() + await conn.write(newSeq[byte](0)) await conn.write("Hello!") await conn.close()