Skip to content

Commit

Permalink
DISPATCH-2119 Close connection if Node creation fails, to prevent fd …
Browse files Browse the repository at this point in the history
…leaks on macOS
  • Loading branch information
jiridanek committed Jul 23, 2021
1 parent c30db1c commit b207af3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
9 changes: 7 additions & 2 deletions python/qpid_dispatch/management/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,13 @@ def connect(url=None, router=None, timeout=10, ssl_domain=None, sasl=None,
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):
"""
Expand Down
9 changes: 7 additions & 2 deletions tests/system_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -704,7 +706,10 @@ def is_router_connected(self, router_id, **retry_kwargs):
# 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:
Expand Down
2 changes: 1 addition & 1 deletion tests/system_tests_qdmanage.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def run_qdmanage(self, cmd, input=None, expect=Process.EXIT_OK, address=None):
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]
Expand Down

0 comments on commit b207af3

Please sign in to comment.