Skip to content

Commit 576393d

Browse files
[SB] Link-Detach (#34820)
* if it isnt a user started detach * set error instead of raise + comments * fix mypy issue for self._error * fix pylint * change error condition * fix comment --------- Co-authored-by: Kashif Khan <[email protected]>
1 parent cfcb683 commit 576393d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def __init__(
100100
self._is_closed = False
101101
self._on_link_state_change = kwargs.get("on_link_state_change")
102102
self._on_attach = kwargs.get("on_attach")
103-
self._error = None
103+
self._error: Optional[AMQPLinkError] = None
104104

105105
async def __aenter__(self) -> "Link":
106106
await self.attach()
@@ -244,6 +244,11 @@ async def _incoming_detach(self, frame) -> None:
244244
self._error = error_cls(condition=frame[2][0], description=frame[2][1], info=frame[2][2])
245245
await self._set_state(LinkState.ERROR)
246246
else:
247+
if self.state != LinkState.DETACH_SENT:
248+
# Handle the case of when the remote side detaches without sending an error.
249+
# We should detach as per the spec but then retry connecting
250+
self._error = AMQPLinkError(condition=ErrorCondition.UnknownError,
251+
description="Link detached unexpectedly.", retryable=True)
247252
await self._set_state(LinkState.DETACHED)
248253

249254
async def attach(self) -> None:

sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/link.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def __init__(
9696
self._is_closed = False
9797
self._on_link_state_change = kwargs.get("on_link_state_change")
9898
self._on_attach = kwargs.get("on_attach")
99-
self._error = None
99+
self._error: Optional[AMQPLinkError] = None
100100

101101
def __enter__(self) -> "Link":
102102
self.attach()
@@ -239,6 +239,11 @@ def _incoming_detach(self, frame) -> None:
239239
self._error = error_cls(condition=frame[2][0], description=frame[2][1], info=frame[2][2])
240240
self._set_state(LinkState.ERROR)
241241
else:
242+
if self.state != LinkState.DETACH_SENT:
243+
# Handle the case of when the remote side detaches without sending an error.
244+
# We should detach as per the spec but then retry connecting
245+
self._error = AMQPLinkError(condition=ErrorCondition.UnknownError,
246+
description="Link detached unexpectedly.", retryable=True)
242247
self._set_state(LinkState.DETACHED)
243248

244249
def attach(self) -> None:

0 commit comments

Comments
 (0)