mirror of
https://github.com/status-im/nim-libp2p.git
synced 2025-01-11 05:26:02 +00:00
use race
instead of or
to avoid lockup (#1042)
This commit is contained in:
parent
0b753e7cf2
commit
9059a8aced
@ -266,7 +266,9 @@ method readOnce*(
|
|||||||
raise newLPStreamRemoteClosedError()
|
raise newLPStreamRemoteClosedError()
|
||||||
if channel.recvQueue.len == 0:
|
if channel.recvQueue.len == 0:
|
||||||
channel.receivedData.clear()
|
channel.receivedData.clear()
|
||||||
await channel.closedRemotely or channel.receivedData.wait()
|
try: # https://github.com/status-im/nim-chronos/issues/516
|
||||||
|
discard await race(channel.closedRemotely, channel.receivedData.wait())
|
||||||
|
except ValueError: raiseAssert("Futures list is not empty")
|
||||||
if channel.closedRemotely.done() and channel.recvQueue.len == 0:
|
if channel.closedRemotely.done() and channel.recvQueue.len == 0:
|
||||||
channel.returnedEof = true
|
channel.returnedEof = true
|
||||||
channel.isEof = true
|
channel.isEof = true
|
||||||
|
@ -55,7 +55,9 @@ proc bridge*(connSrc: Connection, connDst: Connection) {.async.} =
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
while not connSrc.closed() and not connDst.closed():
|
while not connSrc.closed() and not connDst.closed():
|
||||||
await futSrc or futDst
|
try: # https://github.com/status-im/nim-chronos/issues/516
|
||||||
|
discard await race(futSrc, futDst)
|
||||||
|
except ValueError: raiseAssert("Futures list is not empty")
|
||||||
if futSrc.finished():
|
if futSrc.finished():
|
||||||
bufRead = await futSrc
|
bufRead = await futSrc
|
||||||
if bufRead > 0:
|
if bufRead > 0:
|
||||||
|
@ -97,7 +97,10 @@ proc handleConn(s: Secure,
|
|||||||
let
|
let
|
||||||
fut1 = conn.join()
|
fut1 = conn.join()
|
||||||
fut2 = sconn.join()
|
fut2 = sconn.join()
|
||||||
await fut1 or fut2 # one join() completes, cancel outstanding join()
|
try: # https://github.com/status-im/nim-chronos/issues/516
|
||||||
|
discard await race(fut1, fut2)
|
||||||
|
except ValueError: raiseAssert("Futures list is not empty")
|
||||||
|
# at least one join() completed, cancel pending one, if any
|
||||||
if not fut1.finished: await fut1.cancelAndWait()
|
if not fut1.finished: await fut1.cancelAndWait()
|
||||||
if not fut2.finished: await fut2.cancelAndWait()
|
if not fut2.finished: await fut2.cancelAndWait()
|
||||||
block:
|
block:
|
||||||
|
@ -68,7 +68,10 @@ proc connHandler*(self: TcpTransport,
|
|||||||
let
|
let
|
||||||
fut1 = client.join()
|
fut1 = client.join()
|
||||||
fut2 = conn.join()
|
fut2 = conn.join()
|
||||||
await fut1 or fut2 # one join() completes, cancel outstanding join()
|
try: # https://github.com/status-im/nim-chronos/issues/516
|
||||||
|
discard await race(fut1, fut2)
|
||||||
|
except ValueError: raiseAssert("Futures list is not empty")
|
||||||
|
# at least one join() completed, cancel pending one, if any
|
||||||
if not fut1.finished: await fut1.cancelAndWait()
|
if not fut1.finished: await fut1.cancelAndWait()
|
||||||
if not fut2.finished: await fut2.cancelAndWait()
|
if not fut2.finished: await fut2.cancelAndWait()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user