Skip to content

Commit e05b180

Browse files
CopilotPallabPaul
andauthored
Fix LRO poller to treat HTTP 404 and 406 as transient during transaction-status polling
Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-python/sessions/6789a40b-e0da-4d5e-9cce-6cd42b9b4bd1 Co-authored-by: PallabPaul <20746357+PallabPaul@users.noreply.github.com>
1 parent 5cc0a07 commit e05b180

3 files changed

Lines changed: 409 additions & 21 deletions

File tree

sdk/confidentialledger/azure-confidentialledger/azure/confidentialledger/_operations/_patch.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import time
1212
from typing import Any, Callable, IO, List, Optional, Union, cast
1313

14-
from azure.core.exceptions import ResourceNotFoundError
14+
from azure.core.exceptions import HttpResponseError, ResourceNotFoundError
1515
from azure.core.polling import PollingMethod, LROPoller, NoPolling
1616

1717
from azure.confidentialledger._operations._operations import (
@@ -55,7 +55,6 @@ def __init__(
5555
self._latest_response: JSON = {}
5656

5757
self._retry_not_found = retry_not_found
58-
self._not_found_count = 0
5958

6059
def initialize(self, client, initial_response, deserialization_callback): # pylint: disable=unused-argument
6160
self._evaluate_response(initial_response)
@@ -102,15 +101,18 @@ def run(self) -> None:
102101
try:
103102
response = self._operation()
104103
self._evaluate_response(response)
105-
except ResourceNotFoundError as not_found_exception:
106-
# We'll allow some instances of resource not found to account for replication
107-
# delay if session stickiness is lost.
108-
109-
self._not_found_count += 1
110-
111-
not_retryable = not self._retry_not_found or self._give_up_not_found_error(not_found_exception)
112-
113-
if not_retryable or self._not_found_count >= 3:
104+
except HttpResponseError as http_exception:
105+
# 404: node doesn't know about the transaction yet (replication lag)
106+
# 406: node knows the transaction but it hasn't committed yet
107+
# Both are transient during transaction-status polling — treat as
108+
# pending so the poller retries.
109+
if http_exception.status_code in (404, 406) and self._retry_not_found:
110+
if (
111+
isinstance(http_exception, ResourceNotFoundError)
112+
and self._give_up_not_found_error(http_exception)
113+
):
114+
raise
115+
else:
114116
raise
115117
if not self.finished():
116118
time.sleep(self._polling_interval_s)

sdk/confidentialledger/azure-confidentialledger/azure/confidentialledger/aio/_operations/_patch.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import asyncio # pylint: disable=do-not-import-asyncio
1313
from typing import Any, Callable, IO, Coroutine, List, Optional, Union, cast
1414

15-
from azure.core.exceptions import ResourceNotFoundError
15+
from azure.core.exceptions import HttpResponseError, ResourceNotFoundError
1616
from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod
1717

1818
from azure.confidentialledger.aio._operations._operations import (
@@ -56,15 +56,18 @@ async def run(self) -> None:
5656
try:
5757
response = await self._operation()
5858
self._evaluate_response(response)
59-
except ResourceNotFoundError as not_found_exception:
60-
# We'll allow some instances of resource not found to account for replication
61-
# delay if session stickiness is lost.
62-
63-
self._not_found_count += 1
64-
65-
not_retryable = not self._retry_not_found or self._give_up_not_found_error(not_found_exception)
66-
67-
if not_retryable or self._not_found_count >= 3:
59+
except HttpResponseError as http_exception:
60+
# 404: node doesn't know about the transaction yet (replication lag)
61+
# 406: node knows the transaction but it hasn't committed yet
62+
# Both are transient during transaction-status polling — treat as
63+
# pending so the poller retries.
64+
if http_exception.status_code in (404, 406) and self._retry_not_found:
65+
if (
66+
isinstance(http_exception, ResourceNotFoundError)
67+
and self._give_up_not_found_error(http_exception)
68+
):
69+
raise
70+
else:
6871
raise
6972
if not self.finished():
7073
await asyncio.sleep(self._polling_interval_s)

0 commit comments

Comments
 (0)