Track all connections (#175)

* adding to do for future refactor

* no mix conn and transport stopping or it will race

* don't use intermediary vars
This commit is contained in:
Dmitriy Ryajov 2020-05-18 09:08:10 -06:00 committed by GitHub
parent 1819502fb5
commit 5583168965
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 9 deletions

View File

@ -335,16 +335,16 @@ proc stop*(s: Switch) {.async.} =
# we want to report erros but we do not want to fail
# or crash here, cos we need to clean possibly MANY items
# and any following conn/transport won't be cleaned up
var futs = newSeq[Future[void]]()
if s.pubSub.isSome:
futs &= s.pubSub.get().stop()
await s.pubSub.get().stop()
futs &= toSeq(s.connections.values).mapIt(s.cleanupConn(it))
futs &= s.transports.mapIt(it.close())
checkFutures(
await allFinished(
toSeq(s.connections.values).mapIt(s.cleanupConn(it))))
futs = await allFinished(futs)
checkFutures(futs)
checkFutures(
await allFinished(
s.transports.mapIt(it.close())))
trace "switch stopped"

View File

@ -71,6 +71,7 @@ proc connHandler*(t: TcpTransport,
if not isNil(t.handler):
t.handlers &= t.handler(conn)
# TODO: store the streamtransport client here
t.connections.add(conn)
t.cleanups &= t.cleanup(conn)