Skip to content

Commit dbc1361

Browse files
authored
fix: [FFM-12506]: Avoid logging endpoint errors if SDK is shutting down (#206)
1 parent bcc7dd0 commit dbc1361

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dependencyResolutionManagement {
44
versionCatalogs {
55
libs {
66
// main sdk version
7-
version('sdk', '1.8.1');
7+
version('sdk', '1.8.2');
88

99
// sdk deps
1010
version('okhttp3', '4.12.0')

src/main/java/io/harness/cf/client/api/InnerClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ public void onConnected() {
209209
@Override
210210
public void onDisconnected(String reason) {
211211

212-
SdkCodes.warnStreamDisconnected(reason);
212+
if (!reason.contains("SDK_SHUTDOWN")) {
213+
SdkCodes.warnStreamDisconnected(reason);
214+
}
213215

214216
if (!closing && !pollProcessor.isRunning()) {
215217
log.debug("onDisconnected triggered, starting poller to get latest flags");

src/main/java/io/harness/cf/client/api/PollingProcessor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public CompletableFuture<List<Segment>> retrieveSegments() {
7171
completableFuture.complete(segments);
7272
} catch (Throwable e) {
7373
log.error(
74-
"Exception was raised when fetching flags data with the message {}", e.getMessage(), e);
74+
"Exception was raised when fetching segments data with the message {}", e.getMessage(), e);
7575
completableFuture.completeExceptionally(e);
7676
}
7777
return completableFuture;
@@ -81,8 +81,7 @@ public void retrieveAll() {
8181
try {
8282
CompletableFuture.allOf(retrieveFlags(), retrieveSegments()).join();
8383
} catch (CompletionException | CancellationException ex) {
84-
log.warn("retrieveAll failed: {} - {}", ex.getClass().getSimpleName(), ex.getMessage());
85-
log.trace("retrieveAll failed", ex);
84+
log.warn("retrieveAll failed: {} - {}", ex.getClass().getSimpleName(), ex.getMessage(), ex);
8685
}
8786
}
8887

src/main/java/io/harness/cf/client/connector/EventSource.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,14 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO
198198
} catch (Throwable ex) {
199199
log.warn("SSE Stream aborted: " + getExceptionMsg(ex));
200200
log.trace("SSE Stream aborted trace", ex);
201-
updater.onDisconnected(getExceptionMsg(ex));
201+
202+
updater.onDisconnected((isShuttingDown.get() ? "SDK_SHUTDOWN: " : "") + getExceptionMsg(ex));
202203
}
203204
}
204205

205206
private String getExceptionMsg(Throwable ex) {
206207
return (ex.getMessage() == null || "null".equals(ex.getMessage()))
207-
? ex.getClass().getSimpleName()
208+
? ex.getClass().getCanonicalName()
208209
: ex.getMessage();
209210
}
210211

src/main/java/io/harness/cf/client/connector/NewRetryInterceptor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public Response intercept(@NotNull Chain chain) throws IOException {
105105
limitReached = !retryForever && tryCount >= maxTryCount;
106106

107107
if (isShuttingDown.get()) {
108-
log.warn(
108+
log.trace(
109109
"Request attempt {} to {} was not successful, [{}], SDK is shutting down, no retries will be attempted",
110110
tryCount,
111111
chain.request().url(),
@@ -147,6 +147,7 @@ int getRetryAfterHeaderInSeconds(Response response) {
147147
try {
148148
seconds = Integer.parseInt(retryAfterValue);
149149
} catch (NumberFormatException ignored) {
150+
log.trace("Unable to parse Retry-After header as integer: {}", retryAfterValue);
150151
}
151152

152153
if (seconds <= 0) {
@@ -156,6 +157,7 @@ int getRetryAfterHeaderInSeconds(Response response) {
156157
seconds = (int) Duration.between(Instant.now(), then.toInstant()).getSeconds();
157158
}
158159
} catch (ParseException ignored) {
160+
log.warn("Unable to parse Retry-After header value: `{}` as integer or date", retryAfterValue);
159161
}
160162
}
161163

0 commit comments

Comments
 (0)