Skip to content

Commit 71de398

Browse files
committed
update according to comments
1 parent a8a0782 commit 71de398

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55
from typing import Any, List, TYPE_CHECKING
6+
import logging
67

78
import uamqp
89

@@ -16,6 +17,8 @@
1617
if TYPE_CHECKING:
1718
from azure.core.credentials import TokenCredential
1819

20+
_LOGGER = logging.getLogger(__name__)
21+
1922

2023
class ServiceBusClient(object):
2124
"""The ServiceBusClient class defines a high level interface for
@@ -96,7 +99,14 @@ def close(self):
9699
:return: None
97100
"""
98101
for handler in self._handlers:
99-
handler.close()
102+
try:
103+
handler.close()
104+
except Exception as exception: # pylint: disable=broad-except
105+
_LOGGER.error(
106+
"Client has met an exception when closing the handler: %r. Exception: %r.",
107+
handler._container_id, # pylint: disable=protected-access
108+
exception,
109+
)
100110
self._handlers.clear()
101111

102112
if self._connection_sharing and self._connection:

sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55
from typing import Any, List, TYPE_CHECKING
6+
import logging
67

78
import uamqp
89

@@ -18,6 +19,8 @@
1819
if TYPE_CHECKING:
1920
from azure.core.credentials import TokenCredential
2021

22+
_LOGGER = logging.getLogger(__name__)
23+
2124

2225
class ServiceBusClient(object):
2326
"""The ServiceBusClient class defines a high level interface for
@@ -139,7 +142,14 @@ async def close(self):
139142
:return: None
140143
"""
141144
for handler in self._handlers:
142-
await handler.close()
145+
try:
146+
await handler.close()
147+
except Exception as exception: # pylint: disable=broad-except
148+
_LOGGER.error(
149+
"Client has met an exception when closing the handler: %r. Exception: %r.",
150+
handler._container_id, # pylint: disable=protected-access
151+
exception,
152+
)
143153
self._handlers.clear()
144154

145155
if self._connection_sharing and self._connection:

sdk/servicebus/azure-servicebus/tests/async_tests/test_sb_client_async.py

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class ServiceBusClientAsyncTests(AzureMgmtTestCase):
2525
async def test_async_sb_client_close_spawned_handlers(self, servicebus_namespace_connection_string, servicebus_queue, **kwargs):
2626
client = ServiceBusClient.from_connection_string(servicebus_namespace_connection_string)
2727

28+
await client.close()
29+
2830
# context manager
2931
async with client:
3032
assert len(client._handlers) == 0

sdk/servicebus/azure-servicebus/tests/test_sb_client.py

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ def test_sb_client_incorrect_queue_conn_str(self, servicebus_queue_authorization
136136
def test_sb_client_close_spawned_handlers(self, servicebus_namespace_connection_string, servicebus_queue, **kwargs):
137137
client = ServiceBusClient.from_connection_string(servicebus_namespace_connection_string)
138138

139+
client.close()
140+
139141
# context manager
140142
with client:
141143
assert len(client._handlers) == 0

0 commit comments

Comments
 (0)