Fix crash on empty write (#930)

This commit is contained in:
Tanguy 2023-07-10 15:52:08 +02:00 committed by GitHub
parent 74c402ed9d
commit 1721f078c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -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())

View File

@ -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()