From 3d10513b3e3f19136ec8ee50fa5f6657400b8d9c Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni Date: Tue, 24 Mar 2020 15:34:02 +0900 Subject: [PATCH] Properly await the handshake end in secure handler --- libp2p/protocols/secure/secure.nim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libp2p/protocols/secure/secure.nim b/libp2p/protocols/secure/secure.nim index a5018b56f..12114a2ca 100644 --- a/libp2p/protocols/secure/secure.nim +++ b/libp2p/protocols/secure/secure.nim @@ -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():