Skip to content

Commit b207af3

Browse files
committed
DISPATCH-2119 Close connection if Node creation fails, to prevent fd leaks on macOS
1 parent c30db1c commit b207af3

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

python/qpid_dispatch/management/client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,13 @@ def connect(url=None, router=None, timeout=10, ssl_domain=None, sasl=None,
122122
path = '_edge/%s/$management' % edge_router
123123
else:
124124
path = '$management'
125-
return Node(Node.connection(url, router, timeout, ssl_domain, sasl,
126-
edge_router=edge_router), path)
125+
connection = Node.connection(url, router, timeout, ssl_domain, sasl, edge_router=edge_router)
126+
try:
127+
return Node(connection, path)
128+
except Exception:
129+
# ownership of connection has not been given to a new Node; close the connection
130+
connection.close()
131+
raise
127132

128133
def __init__(self, connection, path, locales=None):
129134
"""

tests/system_test.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@
5151

5252
import unittest
5353

54+
import proton
55+
import proton.utils
5456
from proton import Message
5557
from proton import Delivery
5658
from proton.handlers import MessagingHandler
5759
from proton.reactor import AtLeastOnce, Container
5860
from proton.reactor import AtMostOnce
5961
from qpid_dispatch.management.client import Node
60-
62+
from qpid_dispatch.management.error import NotFoundStatus
6163

6264
# Optional modules
6365
MISSING_MODULES = []
@@ -704,7 +706,10 @@ def is_router_connected(self, router_id, **retry_kwargs):
704706
# Meantime the following actually tests send-thru to the router.
705707
node = Node.connect(self.addresses[0], router_id, timeout=1)
706708
return retry_exception(lambda: node.query('org.apache.qpid.dispatch.router'))
707-
except:
709+
except (proton.ConnectionException, NotFoundStatus, proton.utils.LinkDetached):
710+
# proton.ConnectionException: the router is not yet accepting connections
711+
# NotFoundStatus: the queried router is not yet connected
712+
# TODO(DISPATCH-2119) proton.utils.LinkDetached: should be removed, currently needed for DISPATCH-2033
708713
return False
709714
finally:
710715
if node:

tests/system_tests_qdmanage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def run_qdmanage(self, cmd, input=None, expect=Process.EXIT_OK, address=None):
100100
return out
101101

102102
def assert_entity_equal(self, expect, actual, copy=None):
103-
"""Copy keys in copy from actual to identity, then assert maps equal."""
103+
"""Copy keys in copy from actual to expect, then assert maps equal."""
104104
if copy:
105105
for k in copy:
106106
expect[k] = actual[k]

0 commit comments

Comments
 (0)