DISPATCH-2119 Close connection if Node creation fails, to prevent fd leaks on macOS
diff --git a/python/qpid_dispatch/management/client.py b/python/qpid_dispatch/management/client.py
index a36d798..9c81cd1 100644
--- a/python/qpid_dispatch/management/client.py
+++ b/python/qpid_dispatch/management/client.py
@@ -122,8 +122,13 @@
             path = '_edge/%s/$management' % edge_router
         else:
             path = '$management'
-        return Node(Node.connection(url, router, timeout, ssl_domain, sasl,
-                                    edge_router=edge_router), path)
+        connection = Node.connection(url, router, timeout, ssl_domain, sasl, edge_router=edge_router)
+        try:
+            return Node(connection, path)
+        except Exception:
+            # ownership of connection has not been given to a new Node; close the connection
+            connection.close()
+            raise
 
     def __init__(self, connection, path, locales=None):
         """
diff --git a/tests/system_test.py b/tests/system_test.py
index 5e7697e..08c96ae 100755
--- a/tests/system_test.py
+++ b/tests/system_test.py
@@ -51,13 +51,15 @@
 
 import unittest
 
+import proton
+import proton.utils
 from proton import Message
 from proton import Delivery
 from proton.handlers import MessagingHandler
 from proton.reactor import AtLeastOnce, Container
 from proton.reactor import AtMostOnce
 from qpid_dispatch.management.client import Node
-
+from qpid_dispatch.management.error import NotFoundStatus
 
 # Optional modules
 MISSING_MODULES = []
@@ -704,7 +706,10 @@
             # Meantime the following actually tests send-thru to the router.
             node = Node.connect(self.addresses[0], router_id, timeout=1)
             return retry_exception(lambda: node.query('org.apache.qpid.dispatch.router'))
-        except:
+        except (proton.ConnectionException, NotFoundStatus, proton.utils.LinkDetached):
+            # proton.ConnectionException: the router is not yet accepting connections
+            # NotFoundStatus: the queried router is not yet connected
+            # TODO(DISPATCH-2119) proton.utils.LinkDetached: should be removed, currently needed for DISPATCH-2033
             return False
         finally:
             if node:
diff --git a/tests/system_tests_qdmanage.py b/tests/system_tests_qdmanage.py
index 7dd0f8f..28b412e 100644
--- a/tests/system_tests_qdmanage.py
+++ b/tests/system_tests_qdmanage.py
@@ -100,7 +100,7 @@
         return out
 
     def assert_entity_equal(self, expect, actual, copy=None):
-        """Copy keys in copy from actual to identity, then assert maps equal."""
+        """Copy keys in copy from actual to expect, then assert maps equal."""
         if copy:
             for k in copy:
                 expect[k] = actual[k]