Skip to content

Commit 4bf2e00

Browse files
fix(octopus): log the full request once when a token retry also fails
A retry only follows a failure, and that failure has just logged the request in full. The retry's gate rightly logs the request briefly, pointing at that line, but its own 401/403 then logged the full request a second time. Skip the beside-failure re-log on a retry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8bbdaba commit 4bf2e00

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎apps/predbat/octopus.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,8 +2334,10 @@ async def async_graphql_query(self, query, request_context, returns_data=True, i
23342334
request_logged = [True, None]
23352335

23362336
def log_request_beside_failure():
2337-
"""Log the full request beside a failure when it was only logged briefly ("as logged in full at ...")."""
2338-
if not request_logged[0] and request_logged[1]:
2337+
"""Log the full request beside a failure when it was only logged briefly ("as logged in full at ...").
2338+
2339+
Not on a retry: only a failure causes one, and that failure has just logged the request in full."""
2340+
if not request_logged[0] and request_logged[1] and _retry_count == 0:
23392341
# Through the gate, so it records this full log: later brief lines name this time, and the hourly re-log counts from it
23402342
self.log_gate.log(self.log, ("request", request_context), query, [request_logged[1]], None, always_full=True)
23412343
request_logged[0] = True

‎apps/predbat/tests/test_octopus_waf_block.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ async def counting_read(resp, url, ignore_errors=False):
200200
failed = True
201201
else:
202202
print("PASS: first-attempt 401 response body logged once")
203+
# The retry's own 401 must not log the full request again: the first attempt has just logged it in full
204+
full_requests = [line for line in lines6b if line.startswith("OctopusAPI: Making GraphQL request to ")]
205+
if len(full_requests) != 1:
206+
print("ERROR: a 401 then a failed retry should log the full request once, got {}".format(full_requests))
207+
failed = True
208+
else:
209+
print("PASS: full request logged once across a failed retry")
203210

204211
if failed:
205212
print("**** Octopus WAF/CloudFront 403 tests FAILED ****")

0 commit comments

Comments
 (0)