Fix possible race condition in asyncstream close (#91)

This commit is contained in:
Giovanni Petrantoni 2020-04-09 23:56:56 +09:00 committed by GitHub
parent 3d745a4b0c
commit 9ea1017a06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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: