canonical / canonical/hardware-observer-operator

Successful final retry incorrectly raises RetriesExhaustedError when max_retry=1

Open Beginner friendly
#550 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
20
Forks
18
Avg merge
1d 5h
Merged PRs (30d)
3

Description

### Description

The Redfish Python library can raise `RetriesExhaustedError` even when the final permitted retry succeeds.

In our environment, the client is configured with:
```
max_retry = 1
```
The request sequence is:
```
Attempt 1 of /redfish/v1/
... connection failure: [Errno 113] No route to host ...

Attempt 2 of /redfish/v1/
Response Time for GET to /redfish/v1/: 0.108... seconds

Attempt 2 successfully receives a valid HTTP response.
```
However, immediately afterward the library raises:
```
redfish.rest.v1.RetriesExhaustedError
```

The relevant code is:
```Python
attempts = 0
restresp = None

while attempts <= max_retry:
attempts = attempts + 1

try:
resp = self._session.request(...)
restresp = RestResponse(restreq, resp)
except Exception as excp:
...
continue
else:
break

if attempts <= self._max_retry:
return restresp
else:
raise RetriesExhaustedError() from cause_exception
```
With max_retry=1, two total attempts are allowed:
```
Attempt 1 -> fails
Attempt 2 -> succeeds
```
After the successful second attempt:
```
attempts = 2
self._max_retry = 1
restresp = valid RestResponse
```
The following check therefore evaluates false:
```
if attempts <= self._max_retry:
```
and RetriesExhaustedError is raised despite the valid response.

### Charm revision

latest/stable

### Juju version

3.6.13

### Cloud

_No response_

### Expected behaviour

If any permitted retry succeeds, the returned `RestResponse` should be returned to the caller.

For example:
```PY
if restresp is not None:
return restresp
else:
raise RetriesExhaustedError() from cause_exception
```

### Reproduce / Test

- Configure the Redfish client with max_retry=1.
- Make the first request fail with a transient connection error.
- Allow the second attempt to succeed.
- Observe that the library still raises RetriesExhaustedError instead of returning the successful response.

### Notes & References

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at the retry loop in the Redfish client request path described in the issue, and reproduce it with max_retry=1: make the first request fail and the second succeed. Verify that any successful RestResponse is returned and that RetriesExhaustedError is raised only when no permitted attempt produces a response.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.