github-code-scanning[bot] commented on code in PR #14714:
URL: https://github.com/apache/druid/pull/14714#discussion_r1282247195


##########
extensions-core/s3-extensions/src/main/java/org/apache/druid/storage/s3/S3TaskLogs.java:
##########
@@ -67,57 +66,65 @@
   public Optional<InputStream> streamTaskLog(final String taskid, final long 
offset) throws IOException
   {
     final String taskKey = getTaskLogKey(taskid, "log");
-    return streamTaskFile(offset, taskKey);
+    return streamTaskFileWithRetry(offset, taskKey);
   }
 
   @Override
   public Optional<InputStream> streamTaskReports(String taskid) throws 
IOException
   {
     final String taskKey = getTaskLogKey(taskid, "report.json");
-    return streamTaskFile(0, taskKey);
+    return streamTaskFileWithRetry(0, taskKey);
   }
 
   @Override
   public Optional<InputStream> streamTaskStatus(String taskid) throws 
IOException
   {
     final String taskKey = getTaskLogKey(taskid, "status.json");
-    return streamTaskFile(0, taskKey);
+    return streamTaskFileWithRetry(0, taskKey);
   }
 
-  private Optional<InputStream> streamTaskFile(final long offset, String 
taskKey) throws IOException
+  /**
+   * Using the retry conditions defined in {@link S3Utils#S3RETRY}.
+   */
+  private Optional<InputStream> streamTaskFileWithRetry(final long offset, 
String taskKey) throws IOException
+  {
+    try {
+      return S3Utils.retryS3Operation(() -> streamTaskFile(offset, taskKey));
+    }
+    catch (Exception e) {
+      throw new IOE(e, "Failed to stream logs from: %s", taskKey);
+    }
+  }
+
+  private Optional<InputStream> streamTaskFile(final long offset, String 
taskKey)
   {
     try {
       final ObjectMetadata objectMetadata = 
service.getObjectMetadata(config.getS3Bucket(), taskKey);
 
-      try {
-        final long start;
-        final long end = objectMetadata.getContentLength() - 1;
+      final long start;
+      final long end = objectMetadata.getContentLength() - 1;
 
-        if (offset > 0 && offset < objectMetadata.getContentLength()) {
-          start = offset;
-        } else if (offset < 0 && (-1 * offset) < 
objectMetadata.getContentLength()) {
-          start = objectMetadata.getContentLength() + offset;
-        } else {
-          start = 0;
-        }
+      if (offset > 0 && offset < objectMetadata.getContentLength()) {
+        start = offset;
+      } else if (offset < 0 && (-1 * offset) < 
objectMetadata.getContentLength()) {

Review Comment:
   ## User-controlled data in arithmetic expression
   
   This arithmetic expression depends on a [user-provided value](1), 
potentially causing an underflow.
   This arithmetic expression depends on a [user-provided value](2), 
potentially causing an underflow.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5326)



-- 
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