From f5508be54430cf5234064a3f4d8ed7be183fd0f1 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 25 Sep 2019 14:12:42 -0600 Subject: [PATCH] yield to chronos in mplex loop --- libp2p/muxers/mplex/coder.nim | 2 +- libp2p/muxers/mplex/mplex.nim | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libp2p/muxers/mplex/coder.nim b/libp2p/muxers/mplex/coder.nim index af406a436..d8d4ec2de 100644 --- a/libp2p/muxers/mplex/coder.nim +++ b/libp2p/muxers/mplex/coder.nim @@ -40,7 +40,7 @@ proc readMplexVarint(conn: Connection): Future[Option[uint]] {.async, gcsafe.} = if res != VarintStatus.Success: return except LPStreamIncompleteError: - debug "unable to read varing", exc = getCurrentExceptionMsg() + trace "unable to read varint", exc = getCurrentExceptionMsg() proc readMsg*(conn: Connection): Future[Option[Msg]] {.async, gcsafe.} = let headerVarint = await conn.readMplexVarint() diff --git a/libp2p/muxers/mplex/mplex.nim b/libp2p/muxers/mplex/mplex.nim index 1c9e7c015..cee4a4409 100644 --- a/libp2p/muxers/mplex/mplex.nim +++ b/libp2p/muxers/mplex/mplex.nim @@ -57,6 +57,10 @@ method handle*(m: Mplex) {.async, gcsafe.} = while not m.connection.closed: let msgRes = await m.connection.readMsg() if msgRes.isNone: + # TODO: this should ideally be poll(timeout = 100) + # but chronos poll() doesnt take a timeout, so it + # might and does hang + await sleepAsync(100.millis) # yield to async loop continue let (id, msgType, data) = msgRes.get()