better exception handling
This commit is contained in:
parent
d83ce4c932
commit
93e5805c01
|
@ -118,7 +118,7 @@ proc internalCleanup(p: PubSub, conn: Connection) {.async.} =
|
|||
|
||||
var peer = p.getPeer(conn.peerInfo, p.codec)
|
||||
await conn.closeEvent.wait()
|
||||
trace "connection closed, cleaning up peer", peer = conn.peerInfo.id
|
||||
trace "pubsub conn closed, cleaning up peer", peer = conn.peerInfo.id
|
||||
await p.cleanUpHelper(peer)
|
||||
|
||||
method handleConn*(p: PubSub,
|
||||
|
|
|
@ -78,7 +78,6 @@ proc handle*(p: PubSubPeer, conn: Connection) {.async.} =
|
|||
await conn.close()
|
||||
|
||||
proc send*(p: PubSubPeer, msgs: seq[RPCMsg]) {.async.} =
|
||||
try:
|
||||
for m in msgs.items:
|
||||
trace "sending msgs to peer", toPeer = p.id, msgs = msgs
|
||||
let encoded = encodeRpcMsg(m)
|
||||
|
@ -98,18 +97,16 @@ proc send*(p: PubSubPeer, msgs: seq[RPCMsg]) {.async.} =
|
|||
continue
|
||||
|
||||
proc sendToRemote() {.async.} =
|
||||
trace "about send message", peer = p.id,
|
||||
try:
|
||||
trace "about to send message", peer = p.id,
|
||||
encoded = digest
|
||||
await p.onConnect.wait()
|
||||
try:
|
||||
trace "sending encoded msgs to peer", peer = p.id,
|
||||
encoded = encoded.buffer.shortLog
|
||||
await p.sendConn.writeLp(encoded.buffer)
|
||||
p.sentRpcCache.put(digest)
|
||||
except CatchableError as exc:
|
||||
trace "unable to send to remote", exc = exc.msg
|
||||
if not(isNil(p.sendConn)):
|
||||
await p.sendConn.close()
|
||||
p.sendConn = nil
|
||||
p.onConnect.clear()
|
||||
|
||||
|
@ -118,13 +115,6 @@ proc send*(p: PubSubPeer, msgs: seq[RPCMsg]) {.async.} =
|
|||
# becomes available
|
||||
asyncCheck sendToRemote()
|
||||
|
||||
except CatchableError as exc:
|
||||
trace "Exception occurred in PubSubPeer.send", exc = exc.msg
|
||||
if not(isNil(p.sendConn)):
|
||||
await p.sendConn.close()
|
||||
p.sendConn = nil
|
||||
p.onConnect.clear()
|
||||
|
||||
proc sendMsg*(p: PubSubPeer,
|
||||
peerId: PeerID,
|
||||
topic: string,
|
||||
|
|
|
@ -244,7 +244,6 @@ proc encodeRpcMsg*(msg: RPCMsg): ProtoBuffer {.gcsafe.} =
|
|||
proc decodeRpcMsg*(msg: seq[byte]): RPCMsg {.gcsafe.} =
|
||||
var pb = initProtoBuffer(msg)
|
||||
|
||||
result.subscriptions = newSeq[SubOpts]()
|
||||
while true:
|
||||
# decode SubOpts array
|
||||
var field = pb.enterSubMessage()
|
||||
|
|
Loading…
Reference in New Issue