Properly await the handshake end in secure handler

This commit is contained in:
Giovanni Petrantoni 2020-03-24 15:34:02 +09:00
parent 0a3e4a764b
commit 3d10513b3e
1 changed files with 4 additions and 3 deletions

View File

@ -42,11 +42,11 @@ proc readLoop(sconn: SecureConn, stream: BufferStream) {.async.} =
await stream.pushTo(msg)
except CatchableError as exc:
trace "exception occurred SecioConn.readLoop", exc = exc.msg
trace "exception occurred Secure.readLoop", exc = exc.msg
finally:
if not sconn.closed:
await sconn.close()
trace "ending secio readLoop", isclosed = sconn.closed()
trace "ending Secure readLoop", isclosed = sconn.closed()
proc handleConn*(s: Secure, conn: Connection, initiator: bool = false): Future[Connection] {.async, gcsafe.} =
var sconn = await s.handshake(conn, initiator)
@ -69,7 +69,8 @@ method init*(s: Secure) {.gcsafe.} =
proc handle(conn: Connection, proto: string) {.async, gcsafe.} =
trace "handling connection"
try:
asyncCheck s.handleConn(conn, false)
# We don't need the result but we definitely need to await the handshake
discard await s.handleConn(conn, false)
trace "connection secured"
except CatchableError as exc:
if not conn.closed():