Fix hidden close issue in AsyncStream.
This commit is contained in:
parent
43eeceb8e5
commit
247e453b71
|
@ -707,7 +707,8 @@ proc close*(rw: AsyncStreamRW) =
|
|||
if not isNil(rw.udata):
|
||||
GC_unref(cast[ref int](rw.udata))
|
||||
rw.state = AsyncStreamState.Closed
|
||||
rw.future.complete()
|
||||
if not(rw.future.finished()):
|
||||
rw.future.complete()
|
||||
when rw is AsyncStreamReader:
|
||||
untrackAsyncStreamReader(rw)
|
||||
elif rw is AsyncStreamWriter:
|
||||
|
@ -718,11 +719,13 @@ proc close*(rw: AsyncStreamRW) =
|
|||
callSoon(continuation)
|
||||
else:
|
||||
rw.exevent.fire()
|
||||
rw.future.addCallback(continuation)
|
||||
elif rw is AsyncStreamWriter:
|
||||
if isNil(rw.wsource) or isNil(rw.writerLoop):
|
||||
callSoon(continuation)
|
||||
else:
|
||||
rw.exevent.fire()
|
||||
rw.future.addCallback(continuation)
|
||||
|
||||
proc closeWait*(rw: AsyncStreamRW): Future[void] =
|
||||
## Close and frees resources of stream ``rw``.
|
||||
|
|
|
@ -179,8 +179,6 @@ proc chunkedReadLoop(stream: AsyncStreamReader) {.async.} =
|
|||
# incoming data anymore.
|
||||
rstream.buffer.forget()
|
||||
|
||||
untrackAsyncStreamReader(rstream)
|
||||
|
||||
proc chunkedWriteLoop(stream: AsyncStreamWriter) {.async.} =
|
||||
var wstream = cast[ChunkedStreamWriter](stream)
|
||||
var exitFut = wstream.exevent.wait()
|
||||
|
@ -277,8 +275,6 @@ proc chunkedWriteLoop(stream: AsyncStreamWriter) {.async.} =
|
|||
wstream.state = AsyncStreamState.Finished
|
||||
break
|
||||
|
||||
untrackAsyncStreamWriter(wstream)
|
||||
|
||||
proc init*[T](child: ChunkedStreamReader, rsource: AsyncStreamReader,
|
||||
bufferSize = ChunkBufferSize, udata: ref T) =
|
||||
init(cast[AsyncStreamReader](child), rsource, chunkedReadLoop, bufferSize,
|
||||
|
|
Loading…
Reference in New Issue