From 9ea1017a06e9b09996075c2b385fa8ea8aefa0b7 Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni Date: Thu, 9 Apr 2020 23:56:56 +0900 Subject: [PATCH] Fix possible race condition in asyncstream close (#91) --- chronos/streams/asyncstream.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chronos/streams/asyncstream.nim b/chronos/streams/asyncstream.nim index cc4695e..6fc194f 100644 --- a/chronos/streams/asyncstream.nim +++ b/chronos/streams/asyncstream.nim @@ -768,10 +768,11 @@ proc close*(rw: AsyncStreamRW) = if rw.closed(): raise newAsyncStreamIncorrectError("Stream is already closed!") + rw.state = AsyncStreamState.Closed + proc continuation(udata: pointer) = if not isNil(rw.udata): GC_unref(cast[ref int](rw.udata)) - rw.state = AsyncStreamState.Closed if not(rw.future.finished()): rw.future.complete() when rw is AsyncStreamReader: