add dedicated closedWithEOF flag

This commit is contained in:
Dmitriy Ryajov 2020-11-30 17:08:31 -06:00
parent 2718ce77f8
commit c4163649a3
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
1 changed files with 5 additions and 1 deletions

View File

@ -38,6 +38,7 @@ type
objName*: string
oid*: Oid
dir*: Direction
closedWithEOF: bool # prevent concurrent calls
LPStreamError* = object of CatchableError
LPStreamIncompleteError* = object of LPStreamError
@ -283,10 +284,13 @@ proc closeWithEOF*(s: LPStream): Future[void] {.async.} =
##
trace "Closing with EOF", s
if s.atEof() or s.closed():
if s.closedWithEOF:
trace "Already closed"
return
# prevent any further calls to avoid triggering
# reading the stream twice (which should assert)
s.closedWithEOF = true
await s.close()
if s.atEof():