Copilot commented on code in PR #11824:
URL: https://github.com/apache/ozone/pull/11824#discussion_r4402851147


##########
hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/security/symmetric/TestDefaultSecretKeyClient.java:
##########
@@ -30,10 +32,35 @@
 import java.time.Instant;
 import org.apache.hadoop.hdds.conf.OzoneConfiguration;
 import org.apache.hadoop.hdds.protocol.SecretKeyProtocol;
+import org.apache.ozone.test.GenericTestUtils;
 import org.junit.jupiter.api.Test;
 
 /** Tests refreshing the signing key through the composite client. */
 class TestDefaultSecretKeyClient {
+  @Test
+  void pollerKeepsRefreshingAfterFailedPolls() throws Exception {
+    OzoneConfiguration conf = new OzoneConfiguration();
+    conf.set(HDDS_SECRET_KEY_ROTATE_DURATION, "1d");
+    conf.set(HDDS_SECRET_KEY_ROTATE_CHECK_DURATION, "10ms");
+    SecretKeyProtocol scm = mock(SecretKeyProtocol.class);
+    ManagedSecretKey oldKey = SecretKeyTestUtil.generateHmac(
+        Instant.now().minus(Duration.ofDays(2)), Duration.ofDays(9));
+    ManagedSecretKey newKey = SecretKeyTestUtil.generateHmac(Instant.now(), 
Duration.ofDays(9));
+    when(scm.getCurrentSecretKey()).thenReturn(oldKey)
+        .thenThrow(new IOException("SCM fetch failed"))
+        .thenThrow(new IllegalStateException("Unexpected failure"))
+        .thenThrow(new LinkageError("Unexpected error"))
+        .thenReturn(newKey);
+    SecretKeyClient client = DefaultSecretKeyClient.create(conf, scm, "test-");
+    try {
+      client.start(conf);
+      GenericTestUtils.waitFor(() -> 
newKey.equals(client.getCurrentSecretKey()), 10, 5_000);
+      verify(scm, times(5)).getCurrentSecretKey();

Review Comment:
   `verify(scm, times(5))` is likely flaky because the scheduled poll interval 
is 10ms; after the cached key becomes `newKey`, the poller can still execute 
again before `verify(...)` runs, making the call count > 5. Prefer asserting 
`atLeast(5)` (or stopping the client immediately after the wait condition is 
met and then verifying), to avoid timing-dependent failures.



##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/symmetric/DefaultSecretKeySignerClient.java:
##########
@@ -148,9 +148,14 @@ private void scheduleSecretKeyPoller(ConfigurationSource 
conf,
 
     LOG.info("Scheduling SecretKeyPoller with initial delay of {} " +
         "and interval of {}", initialDelay, interval);
-    executorService.scheduleAtFixedRate(() -> checkAndRefresh(rotateDuration),
-        initialDelay.toMillis(), interval.toMillis(),
-        TimeUnit.MILLISECONDS);
+    executorService.scheduleAtFixedRate(() -> {
+      try {
+        checkAndRefresh(rotateDuration);
+      } catch (Throwable t) {
+        // Anything thrown from a periodic task suppresses all subsequent 
executions.
+        LOG.warn("Failed to refresh the secret key, will retry at the next 
check", t);

Review Comment:
   Catching `Throwable` will also swallow JVM-fatal conditions (eg 
`VirtualMachineError`/OOM, `ThreadDeath`) and keep the process running in a 
potentially corrupted state. Consider rethrowing those after logging (eg, if `t 
instanceof VirtualMachineError || t instanceof ThreadDeath`) while still 
swallowing expected failures like `Exception` and non-fatal `Error` types you 
explicitly want to tolerate (eg `LinkageError`).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to