Skip to content

Commit 295c432

Browse files
authored
[ServiceBus/EventHub] move async ssl opts to transport constructor (Azure#37655)
* [ServiceBus/EventHub] move async ssl opts to o transport constructor * changelog
1 parent 36387b4 commit 295c432

File tree

8 files changed

+32
-29
lines changed

8 files changed

+32
-29
lines changed

sdk/eventhub/azure-eventhub/CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
## 5.12.2 (2024-10-02)
44

55
### Bugs Fixed
6-
- Implemented backpressure for async consumer to address a memory leak issue. ([#36398](https://github.com/Azure/azure-sdk-for-python/issues/36398))
6+
7+
- Fixed a bug where creating the SSL context in the async clients was making a blocking call outside of the constructor.([#37246](https://github.com/Azure/azure-sdk-for-python/issues/37246))
8+
9+
### Other Changes
10+
11+
- Implemented backpressure for async consumer to address a memory leak issue. ([#36398](https://github.com/Azure/azure-sdk-for-python/issues/36398))
712

813
## 5.12.1 (2024-06-11)
914

sdk/eventhub/azure-eventhub/azure/eventhub/_pyamqp/aio/_transport_async.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -262,23 +262,21 @@ def __init__(
262262
self.sslopts = ssl_opts
263263
self.network_trace_params = kwargs.get('network_trace_params')
264264
self._use_tls = use_tls
265+
try:
266+
self.sslopts = self._build_ssl_opts(self.sslopts)
267+
except FileNotFoundError as exc:
268+
# FileNotFoundError does not have missing filename info, so adding it below.
269+
# Assuming that this must be ca_certs, since this is the only file path that
270+
# users can pass in (`connection_verify` in the EH/SB clients) through sslopts above.
271+
# For uamqp exception parity.
272+
exc.filename = self.sslopts
273+
raise exc
265274

266275
async def connect(self):
267276
try:
268277
# are we already connected?
269278
if self.connected:
270279
return
271-
try:
272-
# Building ssl opts here instead of constructor, so that invalid cert error is raised
273-
# when client is connecting, rather then during creation. For uamqp exception parity.
274-
self.sslopts = self._build_ssl_opts(self.sslopts)
275-
except FileNotFoundError as exc:
276-
# FileNotFoundError does not have missing filename info, so adding it below.
277-
# Assuming that this must be ca_certs, since this is the only file path that
278-
# users can pass in (`connection_verify` in the EH/SB clients) through sslopts above.
279-
# For uamqp exception parity. Remove later when resolving issue #27128.
280-
exc.filename = self.sslopts
281-
raise exc
282280
self.reader, self.writer = await asyncio.open_connection(
283281
host=self.host,
284282
port=self.port,

sdk/eventhub/azure-eventhub/tests/livetest/asynctests/test_negative_async.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,10 @@ async def on_error(partition_context, error):
503503
fully_qualified_namespace=live_eventhub["hostname"],
504504
eventhub_name=live_eventhub["event_hub"],
505505
credential=azure_credential,
506-
connection_verify="cacert.pem",
506+
connection_verify="fakecert.pem",
507507
uamqp_transport=uamqp_transport,
508508
)
509509

510-
# TODO: this seems like a bug from uamqp, should be ConnectError?
511510
async with producer_client:
512511
with pytest.raises(EventHubError):
513512
await producer_client.create_batch(partition_id="0")

sdk/eventhub/azure-eventhub/tests/livetest/synctests/test_negative.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,10 @@ def on_error(partition_context, error):
444444
fully_qualified_namespace=live_eventhub["hostname"],
445445
eventhub_name=live_eventhub["event_hub"],
446446
credential=azure_credential,
447-
connection_verify="cacert.pem",
447+
connection_verify="fakecert.pem",
448448
uamqp_transport=uamqp_transport,
449449
)
450450

451-
# TODO: this seems like a bug from uamqp, should be ConnectError?
452451
with producer_client:
453452
with pytest.raises(EventHubError):
454453
producer_client.create_batch(partition_id="0")

sdk/servicebus/azure-servicebus/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Bugs Fixed
1010

11+
- Fixed a bug where creating the SSL context in the async clients was making a blocking call outside of the constructor.([#37246](https://github.com/Azure/azure-sdk-for-python/issues/37246))
12+
1113
### Other Changes
1214

1315
## 7.12.3 (2024-09-19)

sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/aio/_transport_async.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -262,23 +262,21 @@ def __init__(
262262
self.sslopts = ssl_opts
263263
self.network_trace_params = kwargs.get('network_trace_params')
264264
self._use_tls = use_tls
265+
try:
266+
self.sslopts = self._build_ssl_opts(self.sslopts)
267+
except FileNotFoundError as exc:
268+
# FileNotFoundError does not have missing filename info, so adding it below.
269+
# Assuming that this must be ca_certs, since this is the only file path that
270+
# users can pass in (`connection_verify` in the EH/SB clients) through sslopts above.
271+
# For uamqp exception parity.
272+
exc.filename = self.sslopts
273+
raise exc
265274

266275
async def connect(self):
267276
try:
268277
# are we already connected?
269278
if self.connected:
270279
return
271-
try:
272-
# Building ssl opts here instead of constructor, so that invalid cert error is raised
273-
# when client is connecting, rather then during creation. For uamqp exception parity.
274-
self.sslopts = self._build_ssl_opts(self.sslopts)
275-
except FileNotFoundError as exc:
276-
# FileNotFoundError does not have missing filename info, so adding it below.
277-
# Assuming that this must be ca_certs, since this is the only file path that
278-
# users can pass in (`connection_verify` in the EH/SB clients) through sslopts above.
279-
# For uamqp exception parity. Remove later when resolving issue #27128.
280-
exc.filename = self.sslopts
281-
raise exc
282280
self.reader, self.writer = await asyncio.open_connection(
283281
host=self.host,
284282
port=self.port,

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,9 @@ async def test_custom_endpoint_connection_verify_exception_async(self,
672672
# invalid cert file to connection_verify should fail
673673
client = ServiceBusClient(hostname, credential, connection_verify="fakecertfile.pem", uamqp_transport=uamqp_transport)
674674
async with client:
675+
sender = client.get_queue_sender(servicebus_queue.name)
675676
with pytest.raises(ServiceBusError):
676-
async with client.get_queue_sender(servicebus_queue.name) as sender:
677+
async with sender:
677678
await sender.send_messages(ServiceBusMessage("foo"))
678679

679680
# Skipping on OSX uamqp - it's raising an Authentication/TimeoutError

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,9 @@ def test_custom_endpoint_connection_verify_exception(self,
700700
# invalid cert file to connection_verify should fail
701701
client = ServiceBusClient(hostname, credential, connection_verify="fakecertfile.pem", uamqp_transport=uamqp_transport)
702702
with client:
703+
sender = client.get_queue_sender(servicebus_queue.name)
703704
with pytest.raises(ServiceBusError):
704-
with client.get_queue_sender(servicebus_queue.name) as sender:
705+
with sender:
705706
sender.send_messages(ServiceBusMessage("foo"))
706707

707708
# Skipping on OSX uamqp - it's raising an Authentication/TimeoutError

0 commit comments

Comments
 (0)