File dont-retry-bad-requests.patch of Package google-guest-oslogin.39852
From 3419025d7217b3a4b67b3659b91892dc7e1489f2 Mon Sep 17 00:00:00 2001
From: Amelia Crate <acrate@google.com>
Date: Wed, 26 Jun 2024 11:03:02 -0700
Subject: [PATCH] Don't retry bad request responses
These are returned for incorrect request paramaters (non-utf8, characters not allowed in usernames, etc.) and repeating the request without changing the parameters is pointless.
---
src/oslogin_utils.cc | 4 ++++
test/oslogin_utils_test.cc | 1 +
2 files changed, 5 insertions(+)
diff --git a/src/oslogin_utils.cc b/src/oslogin_utils.cc
index 7c09d22..aad560f 100644
--- a/src/oslogin_utils.cc
+++ b/src/oslogin_utils.cc
@@ -422,6 +422,10 @@ bool ShouldRetry(long http_code) {
// Metadata key does not exist, no point of retrying.
return false;
}
+ if (http_code == 400) {
+ // Request parameters are bad, no point of retrying.
+ return false;
+ }
return true;
}
diff --git a/test/oslogin_utils_test.cc b/test/oslogin_utils_test.cc
index cf5a805..0646a34 100644
--- a/test/oslogin_utils_test.cc
+++ b/test/oslogin_utils_test.cc
@@ -463,6 +463,7 @@ TEST(GetGroupByTest, GetGroupByGIDSucceeds) {
TEST(CurlClient, RetryLogic) {
ASSERT_FALSE(ShouldRetry(200));
ASSERT_FALSE(ShouldRetry(404));
+ ASSERT_FALSE(ShouldRetry(400));
ASSERT_TRUE(ShouldRetry(429));
}