fix: revert to proper exception handling

This commit is contained in:
Dmitriy Ryajov 2019-11-29 13:44:37 -06:00 committed by zah
parent dde8c01448
commit 9e437a681b
1 changed files with 7 additions and 3 deletions

View File

@ -894,8 +894,9 @@ proc openStream*(api: DaemonAPI, peer: PeerID,
stream.flags.incl(Outbound) stream.flags.incl(Outbound)
stream.transp = transp stream.transp = transp
result = stream result = stream
finally: except Exception as exc:
await api.closeConnection(transp) await api.closeConnection(transp)
raise exc
proc streamHandler(server: StreamServer, transp: StreamTransport) {.async.} = proc streamHandler(server: StreamServer, transp: StreamTransport) {.async.} =
var api = getUserData[DaemonAPI](server) var api = getUserData[DaemonAPI](server)
@ -932,12 +933,14 @@ proc addHandler*(api: DaemonAPI, protocols: seq[string],
protocols)) protocols))
pb.withMessage() do: pb.withMessage() do:
api.servers.add(P2PServer(server: server, address: maddress)) api.servers.add(P2PServer(server: server, address: maddress))
finally: except Exception as exc:
for item in protocols: for item in protocols:
api.handlers.del(item) api.handlers.del(item)
server.stop() server.stop()
server.close() server.close()
await server.join() await server.join()
raise exc
finally:
await api.closeConnection(transp) await api.closeConnection(transp)
proc listPeers*(api: DaemonAPI): Future[seq[PeerInfo]] {.async.} = proc listPeers*(api: DaemonAPI): Future[seq[PeerInfo]] {.async.} =
@ -1298,8 +1301,9 @@ proc pubsubSubscribe*(api: DaemonAPI, topic: string,
ticket.transp = transp ticket.transp = transp
asyncCheck pubsubLoop(api, ticket) asyncCheck pubsubLoop(api, ticket)
result = ticket result = ticket
finally: except Exception as exc:
await api.closeConnection(transp) await api.closeConnection(transp)
raise exc
proc `$`*(pinfo: PeerInfo): string = proc `$`*(pinfo: PeerInfo): string =
## Get string representation of ``PeerInfo`` object. ## Get string representation of ``PeerInfo`` object.