mirror of https://github.com/vacp2p/nim-libp2p.git
Properly await the handshake end in secure handler
This commit is contained in:
parent
0a3e4a764b
commit
3d10513b3e
|
@ -42,11 +42,11 @@ proc readLoop(sconn: SecureConn, stream: BufferStream) {.async.} =
|
||||||
|
|
||||||
await stream.pushTo(msg)
|
await stream.pushTo(msg)
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
trace "exception occurred SecioConn.readLoop", exc = exc.msg
|
trace "exception occurred Secure.readLoop", exc = exc.msg
|
||||||
finally:
|
finally:
|
||||||
if not sconn.closed:
|
if not sconn.closed:
|
||||||
await sconn.close()
|
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.} =
|
proc handleConn*(s: Secure, conn: Connection, initiator: bool = false): Future[Connection] {.async, gcsafe.} =
|
||||||
var sconn = await s.handshake(conn, initiator)
|
var sconn = await s.handshake(conn, initiator)
|
||||||
|
@ -69,7 +69,8 @@ method init*(s: Secure) {.gcsafe.} =
|
||||||
proc handle(conn: Connection, proto: string) {.async, gcsafe.} =
|
proc handle(conn: Connection, proto: string) {.async, gcsafe.} =
|
||||||
trace "handling connection"
|
trace "handling connection"
|
||||||
try:
|
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"
|
trace "connection secured"
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
if not conn.closed():
|
if not conn.closed():
|
||||||
|
|
Loading…
Reference in New Issue