diff --git a/libp2p/daemon/daemonapi.nim b/libp2p/daemon/daemonapi.nim index d683cc95d..a362904a8 100644 --- a/libp2p/daemon/daemonapi.nim +++ b/libp2p/daemon/daemonapi.nim @@ -894,9 +894,8 @@ proc openStream*(api: DaemonAPI, peer: PeerID, stream.flags.incl(Outbound) stream.transp = transp result = stream - except: + finally: await api.closeConnection(transp) - raise getCurrentException() proc streamHandler(server: StreamServer, transp: StreamTransport) {.async.} = var api = getUserData[DaemonAPI](server) @@ -933,14 +932,12 @@ proc addHandler*(api: DaemonAPI, protocols: seq[string], protocols)) pb.withMessage() do: api.servers.add(P2PServer(server: server, address: maddress)) - except: + finally: for item in protocols: api.handlers.del(item) server.stop() server.close() await server.join() - raise getCurrentException() - finally: await api.closeConnection(transp) proc listPeers*(api: DaemonAPI): Future[seq[PeerInfo]] {.async.} = @@ -1301,9 +1298,8 @@ proc pubsubSubscribe*(api: DaemonAPI, topic: string, ticket.transp = transp asyncCheck pubsubLoop(api, ticket) result = ticket - except: + finally: await api.closeConnection(transp) - raise getCurrentException() proc `$`*(pinfo: PeerInfo): string = ## Get string representation of ``PeerInfo`` object. diff --git a/libp2p/protocols/secure/secio.nim b/libp2p/protocols/secure/secio.nim index 534bcf088..10557ac7b 100644 --- a/libp2p/protocols/secure/secio.nim +++ b/libp2p/protocols/secure/secio.nim @@ -1,4 +1,3 @@ - ## Nim-LibP2P ## Copyright (c) 2019 Status Research & Development GmbH ## Licensed under either of @@ -405,8 +404,8 @@ proc readLoop(sconn: SecureConnection, stream: BufferStream) {.async.} = try: let msg = await sconn.readMessage() await stream.pushTo(msg) - except: - trace "exception in secio", exc = getCurrentExceptionMsg() + except CatchableError as exc: + trace "exception in secio", exc = exc return finally: trace "ending secio readLoop"